gevman/interactive-cli

PHP交互式CLI

1.0.0 2017-04-11 14:14 UTC

This package is auto-updated.

Last update: 2024-09-21 03:23:28 UTC


README

Latest Stable Version Latest Unstable Version License

安装(使用composer)

composer require gevman/interactive-cli

Gevman\Cli\Cli

bool confirm(string $prompt [, bool $default = true])

交互式确认 - 返回用户选择值(Y=true,N=false)
  • $prompt - 提示信息
  • $default - 默认值

void input(&$input [, string $message = ''] [, bool $required = false])

交互式提示用户输入
  • $prompt - 提示信息
  • $default - 默认值

Gevman\Cli\CliOutput output(string $str [, mixed $_ = null])

输出消息
  • $str - 消息或sprintf模式
  • $_ - sprintf参数

Gevman\Cli\CliOutput

Gevman\Cli\CliOutput success()

将输出标记为绿色

Gevman\Cli\CliOutput warning()

将输出标记为黄色

Gevman\Cli\CliOutput error()

将输出标记为红色

Gevman\Cli\CliOutput note()

将输出标记为蓝色

Gevman\Cli\CliOutput endl()

换行

Gevman\Cli\CliOutput cl()

清除当前行

void progressBar(mixed $all [, string $additionalInfo = ''])

显示交互式进度条(消息应为当前键)
  • $all - 总数
  • $additionalInfo - 显示每步的附加信息
require '/path/to/autoload.php';

use Gevman\Cli\Cli;

//basic example
Cli::output('%s - %s', 'hello', 'world')->note()->endl()->output('yesimum')->error()->endl()->endl();

//pregressbar example
$all = 100000;
for ($step = 0; $step < 100000; $step++) {
    Cli::output($step + 1)->progressBar($all, $step);
}