stk2k / argparser
Parser for command line options
Installs: 1 686
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=7.2
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^8.5.15
README
Description
Parser for command line options
Feature
- No need to setup complex configuration
- short options: -abc means a/b/c switches(returns [a=>true, b=>true, c=>true])
- long options: --a-key value/--a-key=value returns associative array(['a-key'=>value])
- ordered options: "command a b c" returns ordered array([a, b, c])
Parameters
ArgParser::parse(array $args = null, array $required =[], array $defaults = []);
Demo
[01] Parse command line
use stk2k\argparser\ArgParser; $args = ArgParser::parse(); // script.php a b -c --favorite-food="Fried potato" print_r($args); //Array //( // [0] => /path/to/script.php // [1] => a // [2] => b // [-c] => 1 // [--favorite-food] => Fried potato //)
Requirement
PHP 7.2 or later
Installing stk2k/argparser
The recommended way to install stk2k/argparser is through Composer.
composer require stk2k/argparser
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
License
Author
Disclaimer
This software is no warranty.
We are not responsible for any results caused by the use of this software.
Please use the responsibility of the your self.