alphayax / get_opt

A tiny library to provide support abouts args given to a script

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get Opt

A library to manage scripts arguments

Latest Stable Version Latest Unstable Version pakagist

Travis Coverage Status Codacy Badge

License Total Downloads

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

About

A tiny library to provide support abouts args given to a script


Languages

Language:PHP 100.0%