djiele / command-line-parser
灵活的命令行解析器
dev-master
2020-08-21 15:33 UTC
This package is not auto-updated.
Last update: 2024-09-29 11:18:13 UTC
README
受 PHP getopt 解析器启发的灵活命令行解析器。支持短选项和长选项,紧凑和内联选项。
安装
您可以通过 composer 安装此包
composer require djiele/command-line-parser dev-master
用法
./demo.php -dw ./logs --script ./bin/run.php --dont-watch ./run.pid -k9 -ak -- inline option
require_once __DIR__'./vendor/autoload.php'; use Djiele\Script\CommandLineParser; $opts = [ 'dw' => 'dont-watch:', // required option 's:' => 'script:', // required option 'k' => 'kill-signal::', // optional 'ak' => 'auto-kill', // === true if set 'h' => 'help' // === true if set ]; $args = new CommandLineParser($opts); var_export($args->parse());
returns:
array (
'dont-watch' =>
array (
0 => './logs',
1 => './run.pid',
),
'script' => './bin/run.php',
'kill-signal' => '9',
'auto-kill' => true,
'<inline>' => 'inline option',
)