@@ -9,9 +9,9 @@ Provide some useful utils for the php CLI.
9
9
10
10
- Parse CLI arguments and options
11
11
- Console color render
12
- - CLI env information helper
13
12
- CLI code highlighter
14
- - Build simple cli application
13
+ - Build simple CLI application
14
+ - CLI env information helper
15
15
16
16
## Install
17
17
@@ -42,21 +42,25 @@ use Toolkit\Cli\App;
42
42
$app = new App([
43
43
'desc' => 'this is my cli application',
44
44
]);
45
+ ```
45
46
46
- // register commands
47
+ ### register commands
47
48
48
- // use closure
49
+ Use closure:
50
+
51
+ ``` php
49
52
$app->addCommand('test', function ($app) {
50
53
echo "args:\n";
51
54
/** @var Toolkit\Cli\App $app */
52
55
/** @noinspection ForgottenDebugOutputInspection */
53
56
print_r($app->getArgs());
54
57
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:
58
62
59
- // use closure with config
63
+ ``` php
60
64
$app->addByConfig(function ($app) {
61
65
echo "args:\n";
62
66
/** @var Toolkit\Cli\App $app */
@@ -67,9 +71,12 @@ $app->addByConfig(function ($app) {
67
71
'name' => 'cmd2',
68
72
'desc' => 'the description text for the command: test',
69
73
]);
74
+ ```
75
+
76
+ Use an object:
70
77
71
- // Use an object
72
- $app->addObject(new class
78
+ ``` php
79
+ class MyCommand
73
80
{
74
81
public function getHelpConfig(): array
75
82
{
@@ -93,14 +100,23 @@ STR;
93
100
{
94
101
echo "hello\n";
95
102
}
96
- });
103
+ }
97
104
105
+ // add command
106
+ $app->addObject(new MyCommand);
107
+ ```
108
+
109
+ ### Run application
110
+
111
+ ``` php
98
112
// run
99
113
$app->run();
100
114
```
101
115
102
116
Run demo: ` php example/liteApp `
103
117
118
+ ![ cli-app] ( example/cli-app.png )
119
+
104
120
## PHP file highlight
105
121
106
122
> This is inspire jakub-onderka/php-console-highlighter
@@ -114,7 +130,7 @@ $rendered = Highlighter::create()->highlight(file_get_contents(__FILE__));
114
130
\Toolkit\Cli\Cli::write($rendered);
115
131
```
116
132
117
- ![ colors] ( ./ example/cli-php-file-highlight.png)
133
+ ![ colors] ( example/cli-php-file-highlight.png )
118
134
119
135
## Console color
120
136
@@ -128,7 +144,7 @@ Color::println('hello world', 'success');
128
144
echo Color::render('hello world', 'success');
129
145
```
130
146
131
- ![ colors] ( ./ example/terminal-color.png)
147
+ ![ colors] ( example/terminal-color.png )
132
148
133
149
## Cli downloader
134
150
@@ -168,4 +184,4 @@ Made some progress, downloaded 641 kb so far
168
184
169
185
## License
170
186
171
- MIT
187
+ [ MIT] ( LICENSE )
0 commit comments