2017 © Pedro Peláez
 

library argv

Small functional library to interpret CLI arguments

image

troublete/argv

Small functional library to interpret CLI arguments

  • Sunday, October 15, 2017
  • by troublete
  • Repository
  • 1 Watchers
  • 3 Stars
  • 60 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 40 % Grown

The README.md

Argv

Small functional library to interpret CLI arguments ✨, (*1)

Build Status, (*2)

Install

$ composer require troublete/argv

Usage

<?php
require_once 'path/to/autoload.php';

use function Argv\{cleanArguments, getFlags};

$cleanedArguments = cleanArguments($argv);
$flags = getFlags($cleanedArguments);

if ($flags->rainbow) {
    echo 'rainbow 🌈';
}

On CLI execution like $ php file-with-script.php --rainbow the CLI will output rainbow 🌈. (see examples for a working example), (*3)

API

Methods

cleanArguments(array $argv): string

Will remove the script from the input arguments., (*4)

reduceFlagName(string $flagName): string

Will remove - and -- from flags and flag aliases., (*5)

isCommandCall(array $arguments): bool

Will determine by checking the first argument if a command is called or only a flag call is occuring., (*6)

isFlag(string $argument): bool

Will determine if argument is a flag by checking if first two characters are --., (*7)

isFlagAlias(string $argument): bool

Will determine if argument is a flag alias by checking if the first character is -., (*8)

getFlags(array $arguments, array $aliases = []): class@anonymous

Will return an class with all flags (NOT aliases) as public properties, value set to true or the value with the following index of the flag. If aliases are provided in the form like ['f' => 'flag'] the flag flag will be set on script call with only -f., (*9)

getValues(array $arguments): class@anonymous

Will return all provided values encapsulated in a anonymous class (original index will be preserved). With calling ->all() on the returned class an array with all values will be returned, where key is original index and value the value. With calling ->first() the first value will be returned., (*10)

getCommand(array $arguments): string

Alias method to return the command name off the values, if set., (*11)

License

GPL-2.0 Willi Eßer, (*12)

The Versions

15/10 2017

dev-master

9999999-dev

Small functional library to interpret CLI arguments

  Sources   Download

GPL-2.0

The Development Requires

by Willi Eßer

15/10 2017

2.0.0

2.0.0.0

Small functional library to interpret CLI arguments

  Sources   Download

GPL-2.0

The Development Requires

by Willi Eßer

02/10 2017

1.1.0

1.1.0.0

Small functional library to interpret CLI arguments

  Sources   Download

GPL-2.0

The Development Requires

by Willi Eßer

28/09 2017

1.0.0

1.0.0.0

Small functional library to interpret CLI arguments

  Sources   Download

GPL-2.0

The Development Requires

by Willi Eßer