jblond / php-cli
PHP 命令行 / CLI 脚本类
v1.0.10
2023-02-21 08:08 UTC
Requires
- php: >=7.2
README
composer require jblond/php-cli
PHP 命令行 / CLI 脚本类
示例
<?php use jblond\cli\Cli; use jblond\cli\CliColors; $cli = new Cli(); $colors = new CliColors(); $string = $colors->getColoredString('This is a test','red','black'); $cli->output($string); // normal $cli->error($string); // error // This input requires Hello or world as input $cli->input('Hello world: ',array('Hello','world')); // This input requires only test $cli->input('Test2: ', 'test'); // This input requires any input $cli->input('Free input: ', ''); // Question with default N $answer = $cli->input('Do this? y/N', array('y','n','Y','N'), 'N'); echo $answer;
灵感来自 php.net 文档 https://php.ac.cn/manual/en/features.commandline.io-streams.php