1. Go to this page and download the library: Download cheprasov/php-cli-args library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cheprasov / php-cli-args example snippets
$config = [
'name' => 'n',
'age' => 'a',
'sex' => 's'
];
$CliArgs = new CliArgs($config);
echo $CliArgs->getArg('name'); // Alexander
echo $CliArgs->getArg('n'); // Alexander
echo $CliArgs->getArg('age'); // 42
echo $CliArgs->getArg('a'); // 42
echo $CliArgs->getArg('sex'); // m
echo $CliArgs->getArg('s'); // m
$config = [
// You should specify key as name of option from the command line argument list.
// Example, name <param-name> for --param-name option
'param-name' => [
'alias' => 'p',
// [optional], [string]
// Alias helps to have short or long name for this key.
// Example, name <p> for -p option
'default' => false,
// [optional], [mixed], [default = null]
// Default value will returned if param is not setted
// or params has not value.
'help' => 'Some description about param',
// [optional], [string]
// Text that will returned, if you request help
'filter' => 'int',
// [optional], [string | array | callable]
// Filter for the return value.
// You can use next filters: flag, bool, int, float, help, json, <array>, <function>
// 'int' - cast to integer before return.
// 'float' - cast to float before return.
// 'bool' - cast to bool before return. Yes, true, 1 = TRUE, other = FALSE
// 'json' - decode JSON data before return.
// 'flag' - will return TRUE, if key is exists in command line argument list, otherwise - FALSE
// <array> - use array for enums. Example use ['a', 'b', 'c'] to get only one of these.
// <callable> - use function($value, $default) { ... } to process value by yourself
]
];
$CliArgs = new CliArgs($config);