Argile
, (*1)
Create, get, write options and autogenerated help messages for your CLI PHP applicationsā¦, (*2)
Basic usage about values and switches
Quick first simple example with only one switch:, (*3)
``` php
use Malenki\Argile\Options as Options;, (*4)
$opt = Options::getInstance();, (*5)
$opt->newSwitch('switch')
->short('s')
->help('I am a very simple switch arg with only short form.')
;, (*6)
$opt->parse();, (*7)
if($opt->has('switch'))
{
printf("\"switch\" arg selected!\n");
}
exit();, (*8)
So, if your PHP CLI application is into `yourapp` executable file, then you can call it like that:
$ yourapp -s
"switch" arg selected!, (*9)
Without options, calling it will give help message:
$ yourapp
Usage: complex.php [OPTIONS]ā¦, (*10)
-s I am a very simple switch arg with only short
form., (*11)
-h, --help Display this help message and exit, (*12)
Second example with switch, values, short, long and required options:
```php
use Malenki\Argile\Options as Options;
$opt = Options::getInstance();
$opt->newSwitch('switch')
->short('s')
->help('I am a very simple switch arg with only short form.')
;
$opt->newValue('foo')
->required()
->short('f')
->long('foo')
->help('I am a simple required arg with short and long forms.')
;
$opt->parse();
if($opt->has('switch'))
{
printf("\"switch\" arg selected!\n");
}
if($opt->has('foo'))
{
printf("\"foo\" arg selected! Its value is: \"%s\"\n", $opt->get('foo'));
}
exit();
Advanced usage of values and switches
You can customize variable name into help text of each option:, (*13)
use Malenki\Argile\Options as Options;
$opt = Options::getInstance();
$opt->newValue('foo')
->required()
->short('f')
->long('foo')
->help('I am a simple required value with short and long forms.', 'FILE')
;
//...
You can group options together. Easy, you have to create group, and when you create options, you put the group name has second argument:, (*14)
use Malenki\Argile\Options as Options;
$opt = Options::getInstance();
$opt->addGroup('one', 'Optional title for first group');
$opt->addGroup('two', 'Optional title for second group');
$opt->newSwitch('switch', 'one')
->short('s')
->help('I am a very simple switch arg with only short form.')
;
$opt->newValue('foo', 'one')
->required()
->short('f')
->long('foo')
->help('I am a simple required arg with short and long forms.')
;
$opt->newValue('bar', 'two')
->short('b')
->long('bar')
->help('I am a simple arg with short and long forms.')
;
//...
Later, if you can help, options will be grouped and group's name is shown if it has one., (*15)
Detect and get arguments
Detecting and getting arguments is simple, just use hasArgument()
and getArguments()
methods respectively. The second one returns an array., (*16)
You can define some informations about your app that will be used into help message:, (*17)
- Synopsis (you can add several synopsis lines, see example files)
- Version
- Description
More
You can have "flexible" help output message, that fit your terminal width, or you can leave at default with of 80 columns., (*18)
If you want this text adjustment, do just following:, (*19)
use Malenki\Argile\Options as Options;
$opt = Options::getInstance();
$opt->flexible(); // yes, that's all
// and add your options and other thingā¦
You can apply color and bold on labels and options:, (*20)
use Malenki\Argile\Options as Options;
$opt = Options::getInstance();
$opt->labelColor('red'); // color for labels
$opt->optColor('red'); // color for options
$opt->bold(); // labels and options becomes bold
// and add your options and other thingā¦
Colorsā names are the same as foreground colors defined into Ansi project., (*21)
To see Argile in action, please look at examples
directory and run scripts inside it!, (*22)
MIT Open Source License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:, (*23)
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., (*24)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE., (*25)