Skip to content

Commit 9f1e747

Browse files
committed
update readme
1 parent 4ed2ae8 commit 9f1e747

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,64 @@ $app = new App([
4343
'desc' => 'this is my cli application',
4444
]);
4545

46+
// register commands
4647

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();
47100
```
48101

102+
Run demo: `php example/liteApp`
103+
49104
## PHP file highlight
50105

51106
> This is inspire jakub-onderka/php-console-highlighter

example/liteApp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ $app->addCommand('test', function ($app) {
2525
'desc' => 'the description text for the command: test',
2626
]);
2727

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+
2840
// Use an object
2941
$app->addObject(new class
3042
{
@@ -35,13 +47,13 @@ Options:
3547
--info Output some information
3648
3749
Example:
38-
{{command}}
50+
{{fullCmd}}
3951
4052
STR;
4153

4254
return [
4355
'name' => 'list',
44-
'desc' => 'list all swoft components in src/ dir',
56+
'desc' => 'list all directory name in src/',
4557
'help' => $help,
4658
];
4759
}

0 commit comments

Comments
 (0)