alphayax / get_opt
Utility class for manage scripts arguments
Installs: 8 644
Dependents: 1
Suggesters: 1
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alphayax/get_opt
Requires (Dev)
- codacy/coverage: dev-master
- phpunit/phpcov: 2.*
- phpunit/phpunit: ^4.8.9
README
A library to manage scripts arguments
Features
- Singleton pattern
- Auto generate help
- Manage short and long option (-a --abc)
- Manage values and multiple values (-v /toto -v /tutu)
- Manage required options
Examples
Check if a parameter (specified via a letter or a name) is set
$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();
Get the value of the --file option
$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(); }
Auto-generated Help
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