phico/cli

Phico的轻量级终端支持

dev-main 2024-09-04 10:40 UTC

This package is auto-updated.

Last update: 2024-09-04 10:40:28 UTC


README

Phico的轻量级终端支持Phico

安装

使用composer

composer require phico/cli

使用

CLI提供了一些有用的方法来处理终端交互。

当你创建自己的命令时非常有用。

Cli

向终端写入一行文本

$input = write('Hello world');
在同一行继续
write(', this is Phico', $newline = false);
颜色支持

使用error(), info(), success(), warning()来使用不同的高亮颜色。

请求用户输入

$input = prompt('What is your name? ');
限制响应中的选项
// only one of red, blue or green is accepted
$input = prompt('What is your favourite colour? ', [
    'red',
    'blue',
    'green
]);

写入标题

$input = title('This will be underlined');

// This will be underlined
// =======================

绘制表格

$data = [
    ['Kermit', 'Green'],
    ['Fozzy Bear', 'Brown'],
    ['Miss Piggy', 'Pink'],
    ['Gonzo', 'Blue'],
];
$headings = [ 'Name', 'Colour' ];

$input = table($data, $headings);

参数

参数通过将其组织为标志(短或长)、参数和值来处理终端输入。

标志

使用单个短横线指定单字符标志

phico -v

可以使用单个短横线设置多个单字符标志

phico -vrt

使用has()检查标志是否设置

phico -vrt
$args->has('v'); // true
$args->has('r'); // true
$args->has('t'); // true

$args->has('a'); // false

问题

CLI被认为是功能完整的,但是如果你发现它在行为或性能方面有任何错误或问题,请创建一个问题,如果可能,请提交一个带有修复的pull request。

请确保根据需要更新测试。

对于重大更改,请首先打开一个问题来讨论你想要更改的内容。

许可

BSD-3-Clause