jlaso / console-args
argv 全局的包装器
dev-master
2018-11-14 20:25 UTC
Requires
- php: >=5.3
This package is auto-updated.
Last update: 2024-09-15 10:37:53 UTC
README
console-args
这是一个 argv 全局的包装器
参数和选项的区别是
- 参数是如
--help
这样的字符串 - 选项是如
--file=filename
这样的字符串 - 没有
--
的其他参数不会识别,因为这个包装器的魔法在于它不关心参数/选项的顺序
版本
1.0.0
安装
通过 composer.json 添加模块,在 require 子句中添加
{
"jlaso/console-args": "1.0.0"
}
使用示例
$consoleArgs = new ConsoleArgs($argv, array('help'), array('arg1', 'arg2'));
if($consoleArgs->hasHelp){
print <<<EOD
Please, use this arguments to invoke this command:
--help \tto see this help
--arg1=filename \tthe first argument
--arg2=filename\toptional, the second argument
EOD;
exit();
}
$arg1 = $consoleArgs->getArg1;
$arg2 = $consoleArgs->getArg2;
许可证
MIT