Clinch is a lightweight, no singing no dancing command line argument parser that acts as a
wrapper to the getopt
function native to PHP.
It provides a simple and friendly API that makes working with command line arguments a lot more pleasant.
Clinch is installed via Composer by running the following
composer require olliesplayground/clinch
Clinch is used in the following way
example.php
<?php
require_once 'vendor/autoload.php';
use Clinch\Options;
$options = new Options();
$option = $options->newOption('l');
$option->setLongName('locale');
$locale = $options->getOptionValue('l');
echo "Locale: $locale\n"
Then from the command line, this can be executed as so
php example.php -len
Locale: en
or
php example.php --locale=de
Locale: de
Create a new Option and add it. Returns the new Option object
Add a new Option object
Check whether an option exists
Get all Options objects
Returns an Option if it exists, null
otherwise
Gets the value of an option, if it has been provided via the command line
Sets the short name of an option
Sets the long name of an option
Sets the value of an option
Sets the type of an option, possible values are
Option::TYPE_FLAG
- the option is not expecting a value, if provided the value will be set to true
Option::TYPE_OPTIONAL
- the option is optional. This is the default setting
Option::TYPE_REQUIRED
- the option is required.
Get the short name
Get the long name. Will return null
if not set.
Get the type of an option
Get the value of an option, if it has been provided via the command line, null
otherwise
Creates the short options string as required by getopt
Creates the long options array as required by getopt
Parses the values provided by getopt
Gets the value for an option, if provided via the command line