@@ -9,9 +9,9 @@ Provide some useful utils for the php CLI.
99
1010- Parse CLI arguments and options
1111- Console color render
12- - CLI env information helper
1312- CLI code highlighter
14- - Build simple cli application
13+ - Build simple CLI application
14+ - CLI env information helper
1515
1616## Install
1717
@@ -42,21 +42,25 @@ use Toolkit\Cli\App;
4242$app = new App([
4343 'desc' => 'this is my cli application',
4444]);
45+ ```
4546
46- // register commands
47+ ### register commands
4748
48- // use closure
49+ Use closure:
50+
51+ ``` php
4952$app->addCommand('test', function ($app) {
5053 echo "args:\n";
5154 /** @var Toolkit\Cli\App $app */
5255 /** @noinspection ForgottenDebugOutputInspection */
5356 print_r($app->getArgs());
5457
55- }, [
56- 'desc' => 'the description text for the command: test',
57- ]);
58+ }, 'the description text for the command: test');
59+ ```
60+
61+ Use closure with config:
5862
59- // use closure with config
63+ ``` php
6064$app->addByConfig(function ($app) {
6165 echo "args:\n";
6266 /** @var Toolkit\Cli\App $app */
@@ -67,9 +71,12 @@ $app->addByConfig(function ($app) {
6771 'name' => 'cmd2',
6872 'desc' => 'the description text for the command: test',
6973]);
74+ ```
75+
76+ Use an object:
7077
71- // Use an object
72- $app->addObject(new class
78+ ``` php
79+ class MyCommand
7380{
7481 public function getHelpConfig(): array
7582 {
@@ -93,14 +100,23 @@ STR;
93100 {
94101 echo "hello\n";
95102 }
96- });
103+ }
97104
105+ // add command
106+ $app->addObject(new MyCommand);
107+ ```
108+
109+ ### Run application
110+
111+ ``` php
98112// run
99113$app->run();
100114```
101115
102116Run demo: ` php example/liteApp `
103117
118+ ![ cli-app] ( example/cli-app.png )
119+
104120## PHP file highlight
105121
106122> This is inspire jakub-onderka/php-console-highlighter
@@ -114,7 +130,7 @@ $rendered = Highlighter::create()->highlight(file_get_contents(__FILE__));
114130\Toolkit\Cli\Cli::write($rendered);
115131```
116132
117- ![ colors] ( ./ example/cli-php-file-highlight.png)
133+ ![ colors] ( example/cli-php-file-highlight.png )
118134
119135## Console color
120136
@@ -128,7 +144,7 @@ Color::println('hello world', 'success');
128144echo Color::render('hello world', 'success');
129145```
130146
131- ![ colors] ( ./ example/terminal-color.png)
147+ ![ colors] ( example/terminal-color.png )
132148
133149## Cli downloader
134150
@@ -168,4 +184,4 @@ Made some progress, downloaded 641 kb so far
168184
169185## License
170186
171- MIT
187+ [ MIT] ( LICENSE )
0 commit comments