2017 © Pedro PelĆ”ez
 

library argile

CLI app now easy when using args!

image

malenki/argile

CLI app now easy when using args!

  • Saturday, June 14, 2014
  • by malenki
  • Repository
  • 1 Watchers
  • 3 Stars
  • 3,157 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 0 Forks
  • 4 Open issues
  • 13 Versions
  • 7 % Grown

The README.md

Argile

Latest Stable Version Total Downloads Latest Unstable Version License, (*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)

Meta information about CLI app

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)

The Versions

14/06 2014

dev-master

9999999-dev https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

13/06 2014

dev-develop

dev-develop https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

21/04 2014

dev-feature/3.1

dev-feature/3.1 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

21/02 2014

3.0

3.0.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

20/02 2014

dev-feature/ticket-12

dev-feature/ticket-12 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

03/12 2013

2.5

2.5.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

13/11 2013

2.4

2.4.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

05/11 2013

dev-feature/ticket-13

dev-feature/ticket-13 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

 

cli optget arg

29/10 2013

2.3

2.3.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cli optget arg

29/10 2013

2.2

2.2.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cli optget arg

20/10 2013

2.1

2.1.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cli optget arg

20/08 2013

2.0

2.0.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cli optget arg

18/08 2013

1.0

1.0.0.0 https://github.com/malenkiki/argile

CLI app now easy when using args!

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

cli optget arg