samejack/php-argv

PHP CLI arguments parse.

1.0.3 2020-07-15 12:28 UTC

This package is auto-updated.

Last update: 2024-11-17 12:23:51 UTC


README

Latest Stable Version Build Status Coverage Status License

PHP CLI (command-line interface) argurments parser. PHP-Argv can parse rich pattern, such as the follows

Install by composer

composer require samejack/php-argv

CLI Example

$ ./example/bin-cli -h 127.0.0.1 -u=user -p passwd --debug --max-size=3 test
Array
(
    [h] => 127.0.0.1
    [u] => user
    [p] => passwd
    [debug] => 1
    [max-size] => 3
    [test] => 1
)

PHP Example

<?php
require_once(__DIR__ . '/vendor/autoload.php');

$argvParser = new \samejack\PHP\ArgvParser();

$string = '-h 127.0.0.1 -u=user -p passwd --debug --max-size=3 test';

print_r($argvParser->parseConfigs($string));

Output:

Array
(
    [h] => 127.0.0.1
    [u] => user
    [p] => passwd
    [debug] => 1
    [max-size] => 3
    [test] => 1
)

License

Apache License 2.0