https://github.com/phalcon/cli-options-parser
Command line arguments/options parser to use in Phalcon applications.
https://github.com/phalcon/cli-options-parser
cli command command-line getopt line option parser phalcon
Last synced: 3 months ago
JSON representation
Command line arguments/options parser to use in Phalcon applications.
- Host: GitHub
- URL: https://github.com/phalcon/cli-options-parser
- Owner: phalcon
- License: mit
- Created: 2018-03-22T16:03:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-12-08T20:15:24.000Z (10 months ago)
- Last Synced: 2025-05-27T22:11:28.912Z (4 months ago)
- Topics: cli, command, command-line, getopt, line, option, parser, phalcon
- Language: PHP
- Homepage: https://phalcon.io
- Size: 118 KB
- Stars: 17
- Watchers: 12
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Cop
[](https://github.com/php-pds/skeleton)



Command line arguments/options parser.
## Requirements
* PHP >= 8.0
## Installing via [Composer](https://getcomposer.org)
Install composer in a common location or in your project:
```bash
composer require phalcon/cli-options-parser
```## Usage
```php
use 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 gets booleans:
$parser->getBoolean('foo');// Get param `foo` or return TRUE as a default value
$parser->getBoolean('foo', true);
```### Examples
```
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',
]php test.php \
plain-arg \
--foo \
--bar=baz \
--funny="spam=eggs" \
--also-funny=spam=eggs \
'plain arg 2'
-abc \
-k=value \
"plain arg 3" \
--s="original" \
--s='overwrite' \
--s
[
0 => 'plain-arg',
'foo' => true,
'bar' => 'baz',
'funny' => 'spam=eggs',
'also-funny' => 'spam=eggs',
1 => 'plain arg 2',
'a' => true,
'b' => true,
'c' => true,
'k' => 'value',
2 => 'plain arg 3',
's' => 'overwrite',
]
```## License
The Cop is open source software licensed under the [MIT License](https://github.com/phalcon/cli-options-parser/blob/master/LICENSE).
© Phalcon Team