Download the PHP package cheprasov/php-cli-args without Composer
On this page you can find all versions of the php package cheprasov/php-cli-args. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cheprasov/php-cli-args
More information about cheprasov/php-cli-args
Files in cheprasov/php-cli-args
Package php-cli-args
Short Description Easy way to gets options from the command line argument list
License MIT
Homepage http://github.com/cheprasov/php-cli-args
Informations about the package php-cli-args
CliArgs v3.0.0 for PHP >= 5.5
About
Class CliArgs helps to get options from the command line argument list easy.
Features
- CliArgs uses $GLOBAL['argv'] as base, and it does not use function getopt().
- It does not implement logic for 'required', it should be in your side.
- It helps to get options easy from command line argument list.
- It generates help info about options based on config.
- Flexible configuration and data filtering.
Note
This class is not workable when register_argc_argv is disabled.
Usage
Example
run
example.php
Config
Note: all params from cli that you want to use should be specified in config, otherwise they will be ignored.
Examples of config:
Example 1
Example 2
Example 3
Example 4
Create a new instance
Methods
new CliArgs(array|null $config = null)
Constructor. If config contents wrong aliases then ConfigErrorException will be thrown.
getArgs(): array
The method returns all passed arguments which is specified in config.
getArg(string $key): mixed | null
Returns value for argument by key. If argument is not set, then it will return default value or null
isFlagExist(string $key, boolean $checkAlias = true): bool
Return true
if key exists, otherwise the method returns false
If $checkAlias
is true
, then the method will check key and alias, and will return true
if key or alias exists.
If $checkAlias
is false
, then the method will check only key and will return true
only if key exists.
getArguments(): array
Get prepared arguments from ARGV
geHelp([string $value = null]): string
Get help
Installation
Composer
Download composer:
wget -nc http://getcomposer.org/composer.phar
and add dependency to your project:
php composer.phar require cheprasov/php-cli-args
Running tests
./vendor/bin/phpunit
Something doesn't work
Feel free to fork project, fix bugs and finally request for pull (do not forget write tests please)