A library to manage scripts arguments
- Singleton pattern
- Auto generate help
- Manage short and long option (-a --abc)
- Manage values and multiple values (-v /toto -v /tutu)
- Manage required options
$Args = \alphayax\utils\cli\GetOpt::getInstance();
$Args->setDescription('This script is a tiny example to show library features');
$verboseOption = $Args->addOpt('v', 'verbose', 'Verbose Mode');
$Args->parse();
$isVerboseMode = $verboseOption->isPresent();
$Args = \alphayax\utils\cli\GetOpt::getInstance();
$Args->setDescription('This script is a tiny example to show library features');
$fileOption = $Args->addOpt('f', 'file', 'File name', true);
$Args->parse();
// Check if file option is specified (via -f or --file)
if( $fileOption->isPresent()){
$fileName = $fileOption->getValue();
}
Example of help output (if the -h or --help flag is specified) :
Description
This script is a tiny example to show library features
Usage
/usr/bin/php a.php [OPTIONS]
Options
-d Debug mode
--dry-run Dry Run mode
--file <value> Specify the file name
-h --help Display help
-n <value> [REQUIRED] Number of lines
-v --verbose Verbose Mode