44[ ![ Php Version] ( https://img.shields.io/badge/php-%3E=5.6.0-brightgreen.svg?maxAge=2592000 )] ( https://packagist.org/packages/inhere/console )
55[ ![ Latest Stable Version] ( http://img.shields.io/packagist/v/inhere/console.svg )] ( https://packagist.org/packages/inhere/console )
66
7- 简洁、功能全面的php命令行应用库。提供控制台参数解析, 颜色风格输出, 用户信息交互, 特殊格式信息显示。
7+ 简洁、功能全面的php命令行应用库。提供控制台参数解析, 命令运行, 颜色风格输出, 用户信息交互, 特殊格式信息显示。
88
99> 无其他库依赖,可以方便的整合到任何已有项目中。
1010
1111- 功能全面的命令行的选项参数解析(命名参数,短选项,长选项 ...)
12- - 命令行应用, 命令行的 ` controller ` , ` command ` 解析运行
12+ - 命令行应用, 命令行的 ` controller ` , ` command ` 解析运行。(支持命令别名)
1313- 命令行中功能强大的 ` input ` , ` output ` 管理、使用
1414- 消息文本的多种颜色风格输出支持(` info ` , ` comment ` , ` success ` , ` danger ` , ` error ` ... ...)
15- - 丰富的特殊格式信息显示(` section ` , ` panel ` , ` padding ` , ` help-panel ` , ` table ` , ` title ` , ` list ` , ` progressBar ` )
16- - 常用的用户信息交互支持(` select ` , ` confirm ` , ` ask/question ` )
15+ - 丰富的特殊格式信息显示(` section ` , ` panel ` , ` padding ` , ` help-panel ` , ` table ` , ` title ` , ` list ` , ` multiList ` , ` progressBar ` )
16+ - 常用的用户信息交互支持(` select ` , ` multiSelect ` , ` confirm ` , ` ask/question ` , ` askPassword/askHiddenInput ` )
1717- 命令方法注释自动解析(提取为参数 ` arguments ` 和 选项 ` options ` 等信息)
1818- 类似 ` symfony/console ` 的预定义参数定义支持(按位置赋予参数值)
1919- 输出是 windows,linux 兼容的,不支持颜色的环境会自动去除相关CODE
3434
3535## 安装
3636
37- - 使用 composer
37+ - 使用 composer 命令
38+
39+ ``` bash
40+ composer require inhere/console
41+ ```
42+
43+ - 使用 composer.json
3844
3945编辑 ` composer.json ` ,在 ` require ` 添加
4046
4147```
4248"inhere/console": "dev-master",
49+
50+ // "inhere/console": "^2.0", // 指定稳定版本
4351// "inhere/console": "dev-php5", // for php5
4452```
4553
@@ -84,10 +92,12 @@ $app->run();
8492
8593然后在命令行里执行 ` php examples/app ` , 立即就可以看到如下输出了:
8694
87- ![ 'output-commands-info '] ( images/example- app.png)
95+ ![ 'app-command-list '] ( docs/screenshots/ app-command-list .png)
8896
8997> ` Independent Commands ` 中的 demo 就是我们上面添加的命令
9098
99+ - ` [alias: ...] ` 命令最后的alias 表明了此命令拥有的别名。
100+
91101## 添加命令
92102
93103添加命令的方式有三种
@@ -104,7 +114,7 @@ $app->command('demo', function (Input $in, Output $out) {
104114}, 'this is message for the command');
105115```
106116
107- ### 继承 ` Inhere\Console\Command `
117+ ### 独立命令
108118
109119通过继承 ` Inhere\Console\Command ` 添加独立命令
110120
@@ -155,7 +165,7 @@ $app->command(TestCommand::class);
155165// $app->command('test1', TestCommand::class);
156166```
157167
158- ### 继承 ` Inhere\Console\Controller `
168+ ### 命令组
159169
160170通过继承 ` Inhere\Console\Controller ` 添加一组命令. 即是命令行的控制器
161171
@@ -171,13 +181,29 @@ class HomeController extends Controller
171181 protected static $description = 'default command controller. there are some command usage examples';
172182
173183 /**
174- * this is a command's description message < info >a color text</info >
184+ * this is a command's description message, < cyan > color text</cyan >
175185 * the second line text
176- * @usage usage message
186+ * @usage {command} [arg ...] [--opt ...]
187+ * @arguments
188+ * arg1 argument description 1
189+ * the second line
190+ * a2,arg2 argument description 2
191+ * the second line
192+ * @options
193+ * -s, --long option description 1
194+ * --opt option description 2
177195 * @example example text one
178196 * the second line example
179197 */
180- public function indexCommand()
198+ public function testCommand()
199+ {
200+ $this->write('hello, welcome!! this is ' . __METHOD__);
201+ }
202+
203+ /**
204+ * a example for use color text output on command
205+ */
206+ public function otherCommand()
181207 {
182208 $this->write('hello, welcome!! this is ' . __METHOD__);
183209 }
@@ -192,13 +218,14 @@ class HomeController extends Controller
192218
193219- 支持的tag有 ` @usage ` ` @arguments ` ` @options ` ` @example `
194220- 当你使用 ` php examples/app home -h ` 时,可以查看到 ` HomeController ` 的所有命令描述注释信息
195- - 当使用 ` php examples/app home:index -h ` 时,可以查看到关于 ` HomeController::indexCommand ` 更详细的信息。包括描述注释文本、` @usage ` 、` @example `
221+
222+ ![ group-command-list] ( docs/screenshots/group-command-list.png )
223+ - 当使用 ` php examples/app home:test -h ` 时,可以查看到关于 ` HomeController::testCommand ` 更详细的信息。包括描述注释文本、` @usage ` 、` @example `
196224
197- > 小提示:注释里面同样支持带颜色的文本输出 ` eg: this is a command's description <info>message</info> `
225+ ![ group- command-list ] ( docs/screenshots/group-command-help.png )
198226
199- - 运行效果(by ` php examples/app home ` ):
227+ > 小提示:注释里面同样支持带颜色的文本输出 ` eg: this is a command's description <info>message</info> `
200228
201- ![ command-group-example] ( ./images/example-for-group.png )
202229
203230更多请查看 [ examples] ( ./examples ) 中的示例代码和在目录下运行示例 ` php examples/app ` 来查看效果
204231
@@ -360,12 +387,24 @@ $output->write('hello <info>world<info>');
360387
361388已经内置了常用的风格:
362389
363- ![ alt text] ( images /output-color-text.png " Title ")
390+ ![ alt text] ( docs/screenshots /output-color-text.png " Title ")
364391
365392来自于类 ` Inhere\Console\Utils\Show ` 。
366393
367394> output 实例拥有 ` Inhere\Console\Utils\Show ` 的所有格式化输出方法。不过都是通过对象式访问的。
368395
396+ - ** 单独使用颜色风格**
397+
398+ ``` php
399+ $style = Inhere\Console\Style\Style::create();
400+
401+ echo $style->render('no color <info >color text</info >');
402+
403+ // 直接使用内置的风格
404+ echo $style->info('message');
405+ echo $style->error('message');
406+ ```
407+
369408### 标题文本输出
370409
371410使用 ` Show::title()/$output->title() `
@@ -403,13 +442,13 @@ echo "Progress:\n";
403442
404443$i = 0;
405444while ($i <= $total) {
406- $bar->send($i);
445+ $bar->send(1);// 发送步进长度,通常是 1
407446 usleep(50000);
408447 $i++;
409448}
410449```
411450
412- ![ show-progress] ( images/show- progress.png)
451+ ![ show-progress] ( docs/screenshots/ progress-demo .png)
413452
414453### 列表数据展示输出
415454
@@ -438,7 +477,9 @@ $data = [
438477Show::aList($data, $title);
439478```
440479
441- > 渲染效果请看下面的预览
480+ > 渲染效果
481+
482+ ![ fmt-list] ( docs/screenshots/fmt-list.png )
442483
443484### 多列表数据展示输出
444485
@@ -467,7 +508,9 @@ $data = [
467508Show::mList($data);
468509```
469510
470- > 渲染效果请看下面的预览
511+ > 渲染效果
512+
513+ ![ fmt-multi-list] ( docs/screenshots/fmt-multi-list.png )
471514
472515### 面板展示信息输出
473516
@@ -489,7 +532,9 @@ $data = [
489532Show::panel($data, 'panel show', '#');
490533```
491534
492- > 渲染效果请看下面的预览
535+ > 渲染效果
536+
537+ ![ fmt-panel] ( docs/screenshots/fmt-panel.png )
493538
494539### 数据表格信息输出
495540
@@ -531,7 +576,7 @@ Show::table($data, 'a table', $opts);
531576
532577> 渲染效果请看下面的预览
533578
534- ![ table-show] ( images /table-show.png)
579+ ![ table-show] ( docs/screenshots /table-show.png)
535580
536581### 快速的渲染一个帮助信息面板
537582
@@ -558,9 +603,9 @@ Show::helpPanel([
558603], false);
559604```
560605
561- ### 渲染效果预览
606+ > 渲染效果预览
562607
563- ![ alt text] ( images/output-format-msg .png " Title ")
608+ ![ alt text] ( docs/screenshots/fmt-help-panel .png " Title ")
564609
565610## 用户交互方法
566611
0 commit comments