File tree Expand file tree Collapse file tree 2 files changed +69
-2
lines changed Expand file tree Collapse file tree 2 files changed +69
-2
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,64 @@ $app = new App([
43
43
'desc' => 'this is my cli application',
44
44
]);
45
45
46
+ // register commands
46
47
48
+ // use closure
49
+ $app->addCommand('test', function ($app) {
50
+ echo "args:\n";
51
+ /** @var Toolkit\Cli\App $app */
52
+ /** @noinspection ForgottenDebugOutputInspection */
53
+ print_r($app->getArgs());
54
+
55
+ }, [
56
+ 'desc' => 'the description text for the command: test',
57
+ ]);
58
+
59
+ // use closure with config
60
+ $app->addByConfig(function ($app) {
61
+ echo "args:\n";
62
+ /** @var Toolkit\Cli\App $app */
63
+ /** @noinspection ForgottenDebugOutputInspection */
64
+ print_r($app->getArgs());
65
+
66
+ }, [
67
+ 'name' => 'cmd2',
68
+ 'desc' => 'the description text for the command: test',
69
+ ]);
70
+
71
+ // Use an object
72
+ $app->addObject(new class
73
+ {
74
+ public function getHelpConfig(): array
75
+ {
76
+ $help = <<<STR
77
+ Options:
78
+ --info Output some information
79
+
80
+ Example:
81
+ {{fullCmd}}
82
+
83
+ STR;
84
+
85
+ return [
86
+ ' name' => 'list',
87
+ 'desc' => 'list all directory name in src/',
88
+ 'help' => $help,
89
+ ];
90
+ }
91
+
92
+ public function __invoke(App $app)
93
+ {
94
+ echo "hello\n";
95
+ }
96
+ });
97
+
98
+ // run
99
+ $app->run();
47
100
```
48
101
102
+ Run demo: ` php example/liteApp `
103
+
49
104
## PHP file highlight
50
105
51
106
> This is inspire jakub-onderka/php-console-highlighter
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ $app->addCommand('test', function ($app) {
25
25
'desc ' => 'the description text for the command: test ' ,
26
26
]);
27
27
28
+ // use closure with config
29
+ $ app ->addByConfig (function ($ app ) {
30
+ echo "args: \n" ;
31
+ /** @var Toolkit\Cli\App $app */
32
+ /** @noinspection ForgottenDebugOutputInspection */
33
+ print_r ($ app ->getArgs ());
34
+
35
+ }, [
36
+ 'name ' => 'cmd2 ' ,
37
+ 'desc ' => 'the description text for the command: test ' ,
38
+ ]);
39
+
28
40
// Use an object
29
41
$ app ->addObject (new class
30
42
{
@@ -35,13 +47,13 @@ Options:
35
47
--info Output some information
36
48
37
49
Example:
38
- {{command }}
50
+ {{fullCmd }}
39
51
40
52
STR ;
41
53
42
54
return [
43
55
'name ' => 'list ' ,
44
- 'desc ' => 'list all swoft components in src/ dir ' ,
56
+ 'desc ' => 'list all directory name in src/ ' ,
45
57
'help ' => $ help ,
46
58
];
47
59
}
You can’t perform that action at this time.
0 commit comments