Skip to content
This repository was archived by the owner on Feb 6, 2019. It is now read-only.

Repository files navigation

Cli

It's like meow, but for PHP.

Build Status

Install

$ composer require troublete/cli

Usage

Some script content, let's assume cli.php.

<?phprequire_once'path/to/vendor/autoload.php';
usefunctionCli\cli;
$app = cli($argv, 'Usage: <flags>');
if ($app->flags->someFlag !== false) {
$app->print($app->flags->someFlag);
exit;
}

By calling the script with the following arguments, it'll output 🌈.

$ php cli.php --someFlag 🌈

For examples see /examples.

API

Functions

cli($arguments, $helpMessage, $flagAliases = [], $showHelp = true, $outputStreams = [])

Function to instantiate an anonymous class instance with relevant information as public properties. So they are exposed and can be used directly.

Arguments
ArgumentTypeDescription
$argumentsarrayThe arguments from which the script shall take the flags and values (should be in most cases $argv).
$helpMessagestringThe help/welcome message that shall be shown on script call with --help or when no arguments are provided (flag based, see $showHelp).
$flagAliasesarrayAn array with short aliases for flags. For example ['h' => 'help'], would allow that -h is used instead of --help.
$showHelpboolFlag to determine if the help message should be shown on call without arguments.
$outputStreamsarrayArray of output streams the print() method will write to when called. (defaults to STDOUT)
Properties
PropertyTypeDescription
composer\stdClassContains the composer package information, read from getcwd() if available.
flagsclass@anonymousContains the flags with simple API to use (see related package argv for more information).
isCommandboolContains the information if the current call is a command call.
commandNamestringContains the current comman name, given it's a command call, else empty.
helpMessagestringContains the help message defined for the CLI.
Methods
MethodDescription
print(string $contents)Method to print something in the set output streams (just to have a common way of doing this, see $outputStreams)

Related Packages

  • Argv - Functional library to parse CLI arguments
  • Crayon - Functional library for colorful CLI output

License

GPL-2.0 © Willi Eßer

About

It's like meow, but for PHP.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages