11# php 命令行应用库
22
3- 简洁功能全面的php命令行应用库 。提供控制台参数解析, 颜色风格输出, 用户信息交互, 特殊格式信息显示
3+ 简洁、功能全面的php命令行应用库 。提供控制台参数解析, 颜色风格输出, 用户信息交互, 特殊格式信息显示
44
5+ - 功能全面的命令行的选项参数解析(命名参数,短选项,长选项 ...)
56- 命令行应用, 命令行的 ` controller ` , ` command ` 解析运行
6- - 功能全面的命令行的选项参数解析
77- 命令行中功能强大的 ` input ` , ` output ` 管理、使用
88- 消息文本的多种颜色风格输出支持(` info ` , ` comment ` , ` success ` , ` danger ` , ` error ` ... ...)
9- - 常用的特殊格式信息显示 (` section ` , ` panel ` , ` padding ` , ` help-panel ` , ` table ` , ` title ` , ` list ` , ` progressBar ` )
9+ - 丰富的特殊格式信息显示 (` section ` , ` panel ` , ` padding ` , ` help-panel ` , ` table ` , ` title ` , ` list ` , ` progressBar ` )
1010- 常用的用户信息交互支持(` select ` , ` confirm ` , ` ask/question ` )
1111- 命令方法注释自动解析(提取为参数 ` arguments ` 和 选项 ` options ` 等信息)
1212- 类似 ` symfony/console ` 的预定义参数定义支持(按位置赋予参数值)
13+ - 输出是 windows,linux 兼容的,不支持颜色的环境会自动去除相关CODE
14+
15+ > 下面所有的特性,效果都是运行 ` examples/ ` 中的示例代码 ` php examples/app ` 展示出来的。下载后可以直接测试体验
1316
1417## [ EN README] ( ./README_en.md )
1518
@@ -97,14 +100,17 @@ $app->command('demo', function (Input $in, Output $out) {
97100- 通过继承 ` Inhere\Console\Command ` 添加独立命令
98101
99102``` php
100- use Inhere\Console\Utils\AnsiCode ;
103+ use Inhere\Console\Command ;
101104
102105/**
103106 * Class Test
104107 * @package app\console\commands
105108 */
106109class TestCommand extends Command
107110{
111+ protected static $name = 'test';
112+ protected static $description = 'this is a test independent command';
113+
108114 /**
109115 * execute
110116 * @param Inhere\Console\IO\Input $input
@@ -153,11 +159,15 @@ class HomeController extends Controller
153159命令组(eg ` HomeController ` ) 中的命令(eg: ` indexCommand ` )上注释是可被解析的。
154160
155161- 当你使用 ` php examples/app home -h ` 时,可以查看到 ` HomeController ` 的所有命令信息
156- - 当使用 ` php examples/app home/ index -h ` 时,可以查看到关于 ` HomeController::indexCommand ` 更详细的信息。包括描述注释文本、` @usage ` 、` @example `
162+ - 当使用 ` php examples/app home: index -h ` 时,可以查看到关于 ` HomeController::indexCommand ` 更详细的信息。包括描述注释文本、` @usage ` 、` @example `
157163
158164> 小提示:注释里面同样支持带颜色的文本输出 ` eg: this is a command's description <info>message</info> `
159165
160- 更多请查看 [ examples] ( ./examples ) 中的示例代码
166+ - 运行效果(by ` php examples/app home ` ):
167+
168+ ![ command-group-example] ( ./images/command-group-example.jpg )
169+
170+ 更多请查看 [ examples] ( ./examples ) 中的示例代码和在目录下运行示例 ` php examples/app ` 来查看效果
161171
162172## 输入
163173
@@ -166,7 +176,7 @@ class HomeController extends Controller
166176在终端中执行如下命令,用于演示参数选项等信息的解析:
167177
168178``` bash
169- $ php examples/app home/ useArg status=2 name=john arg0 -s=test --page=23 --id=154 -e dev -v vvv -d -rf --debug --test=false
179+ $ php examples/app home: useArg status=2 name=john arg0 -s=test --page=23 --id=154 -e dev -v vvv -d -rf --debug --test=false
170180```
171181
172182** 一点说明:**
@@ -187,7 +197,7 @@ $ php examples/app home/useArg status=2 name=john arg0 -s=test --page=23 --id=15
187197
188198``` php
189199echo $input->getScript(); // 'examples/app' 执行的入口脚本文件
190- echo $input->getCommand(); // 'home/ useArg' 解析到的第一个参数将会被认为是命令名称,并且不会再存入到 参数列表中
200+ echo $input->getCommand(); // 'home: useArg' 解析到的第一个参数将会被认为是命令名称,并且不会再存入到 参数列表中
191201echo $input->getFullScript(); // 命令行输入的原样字符串
192202```
193203
@@ -345,7 +355,7 @@ public static function progressBar(int $total, array $opts = [])
345355$total = 120;
346356$bar = Show::progressBar($total, [
347357 'msg' => 'Msg Text',
348- 'doneChar' => '#'
358+ 'doneChar' => '#'// ♥ ■ ☺ ☻ = # Windows 环境下不要使用特殊字符,否则会乱码
349359]);
350360echo "Progress:\n";
351361
@@ -472,7 +482,7 @@ $data = [
472482
473483$opts = [
474484 'showBorder' => true,
475- 'tHead ' => [col1, col2, col3, ...]
485+ 'columns ' => [col1, col2, col3, ...]
476486];
477487Show::table($data, 'a table', $opts);
478488```
0 commit comments