generated from inherelab/php-pkg-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclicmd.php
45 lines (39 loc) · 1.16 KB
/
clicmd.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php declare(strict_types=1);
/**
* This file is part of toolkit/pflag.
*
* @link https://github.com/php-toolkit
* @author https://github.com/inhere
* @license MIT
*/
use Toolkit\Cli\Cli;
use Toolkit\PFlag\CliCmd;
use Toolkit\PFlag\FlagsParser;
require dirname(__DIR__) . '/test/bootstrap.php';
// run demo:
// php example/clicmd.php -h
// php example/clicmd.php --name inhere value1
// php example/clicmd.php --age 23 --name inhere value1
CliCmd::newWith(static function (CliCmd $cmd): void {
$cmd->name = 'demo';
$cmd->desc = 'description for demo command';
// config flags
$cmd->options = [
'age, a' => 'int;the option age, is int',
'name, n' => 'the option name, is string and required;true',
'tags, t' => 'array;the option tags, is array',
];
// or use property
// $cmd->arguments = [...];
// $cmd->getFlags()->setExample($example);
})
->withArguments([
'arg1' => 'this is arg1, is string'
])
->setHandler(function (FlagsParser $fs): void {
Cli::info('options:');
vdump($fs->getOpts());
Cli::info('arguments:');
vdump($fs->getArgs());
})
->run();