vtardia/cli-parser
最新稳定版本:1.0.0
Composer 安装命令:
composer require vtardia/cli-parser
包简介
A command line parser utility for PHP scripts.
关键字:
README 文档
README
CLIParser is a PHP utility that parses the command line of a PHP script detecting short and long options, switches and arguments.
The output is similar to Linux's getopt_long() native function in both behavior and configuration, both long and short options can be validated, for example:
$shortOptions = 'vho:a'; $longOptions = array( array('id', TRUE), array('name', TRUE), array('verbose', FALSE, 'v'), array('output', TRUE, 'o'), );
The above code defines
- the long option
--verbosewith short equivalent-vand no required parameter - the long option
--output, with short equivalent-oand a required parameter - the long options
--idand--namewith required parameters and no short equivalent - the short options
-hand-awith no long equivalent and no required parameter
With CLIParser you can build scripts like:
$ myscript -abc -v -o somefile.log --name=SomeName --other-option OtherValue Argument1 Argument2...ArgumentN
In addition, you can parse the arguments starting from an arbitrary position, so you can have:
$ myscript SomeCommand [OPTIONS] Argument1...ArgumentN
Usage
// require CLIParser.php library file or use an autoloader (eg. Composer) use CLIParser\CliParser; // Define some options $shortOptions = 'vo:'; $longOptions = array( array('verbose', false, 'v'), array('output', true, 'o'), ); // Create a parser... $cli = new CLIParser($shortOptions, $longOptions); // ... and use it! // Executable name or path $program = $cli->program(); // Array of valid options with values $options = $cli->options(); // Array of arguments $arguments = $cli->arguments();
Installation
$ composer require vtardia/cli-parser
Requirements
PHP 5.3 or better, PHPUnit in order to run tests.
Contributing
See CONTRIBUTING file.
Running the Tests
$ composer test
Credits
CLI Parser uses some code written by Patrick Fisher.
Contributor Code of Conduct
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See CODE_OF_CONDUCT file.
License
CLIParser is released under the MIT License. See the bundled LICENSE file for details.
统计信息
- 总下载量: 344
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-26