Command line arguments/options parser.
- PHP >= 8.0
You can install the package using composer
composer require phalcon/cli-options-parseruse Phalcon\Cop\Parser;
$parser = new Parser();
// Parse params from the $argv
$params = $parser->parse($argv);
// Parse params from the $_SERVER['argv']
$params = $parser->parse();
// After parsing input, Parser provides a way to get booleans:
$parser->getBoolean('foo');
// Get param `foo` or return TRUE as a default value
$parser->getBoolean('foo', true);php test.php -az value1 -abc value2
[
'a' => 'value2',
'z' => 'value1',
'b' => 'value2',
'c' => 'value2',
]
php test.php -a value1 -abc value2
[
'a' => 'value2',
'b' => 'value2',
'c' => 'value2',
]
php test.php --az value1 --abc value2
[
'az' => 'value1',
'abc' => 'value2',
]
php test.php --foo --bar=baz --spam eggs
[
'foo' => true,
'bar' => 'baz',
'spam' => 'eggs',
]
php test.php -abc foo
[
'a' => 'foo',
'b' => 'foo',
'c' => 'foo',
]
php test.php arg1 arg2 arg3
[
0 => 'arg1',
1 => 'arg2',
2 => 'arg3',
]
The repository ships a Docker setup for local development and testing. You only need Docker + Docker Compose; the PHP runtime is provided inside the container.
docker compose up -d --build
docker compose exec app composer install
docker compose exec app composer test
appis the Compose service name; the running container iscli-options-parser-app. It stays up via asleep infinitykeepalive, so you candocker compose exec app <cmd>freely.
The image is built for one PHP version at a time via the PHP_VERSION build arg (default 8.4;
supported 8.0–8.4). Because it is a build arg, changing it requires a rebuild:
docker compose up -d --build # PHP 8.4 (default)
PHP_VERSION=8.0 docker compose up -d --build # PHP 8.0| Script | Description |
|---|---|
composer cs |
PHP_CodeSniffer (PSR-12) |
composer cs-fix |
Auto-fix coding-standard issues (phpcbf) |
composer cs-fixer |
PHP CS Fixer (dry-run) |
composer cs-fixer-fix |
Apply PHP CS Fixer |
composer analyze |
PHPStan static analysis (level max) |
composer test |
Unit tests (PHPUnit) |
composer test-coverage |
Tests + Clover coverage (tests/_output/coverage.xml) |
CLI Options Parser is open source software licensed under the BSD-3-Clause License.
© Phalcon Team