The command line interpretation of the Lyra, is done with the help of this library. The commandline options will be parsed with the help internal regex. This command line library can be used in different configurations, to suite the needs of the application. This library is based on the Nate Good's Commando with more functionality like optional parameters, multiple parameters combination and command Dispatcher.
Lyra CMD needs php-mbstring
to be installed.
To Install CMD there are several options available:
This library is available in packagist. So you need to only add this as requirement.
composer require rzuw/lyra-cmd
you can also clone the library and add it using autoload
or using the composer to add as filesystem component.
{
"repositories": [
{
"type": "path",
"url": "/path-to-git-clone"
}
],
"require": {
"rzuw/lyra-cmd": "*"
}
}
You can also add the repository and then require the rzuw/lyra-cmd
.
{
"require": {
"rzuw/lyra-cmd": "*"
},
"repositories": [
{
"type": "vcs",
"url": "ssh://[email protected]/uniwue-rz/lyra-cmd.git"
}
]
}
To use the commandline just create a new instance.
use De\Uniwue\RZ\Lyra\CMD\Command;
$command = new Command();
Add your different options with parameters. You can also link different options together.
$command = new Command();
// Adds the command --bar with shortcut -b with boolean option.
// This means the command --bar will be on or off when called.
// The default value is set to false
$command->option("b")->aka("bar")->describedAs("The bar command")->boolean()->default(false);
// Adds the command --foo with shortcut with boolean option.
// This command will run the bar in the given class and needs always --bar to be set (on) and a username to be set.
// The command has also an optional part which can be there or not but the command will run nevertheless.
$command->option("f")->aka("foo")->describedAs("The foo command")->boolean()->run("bar")->needs(array("b","u"))
->optionals(array("n"));
$command->option("n")->aka("name")->describedAs("The name of the user")->default("");
// This will a required placeholder for the username option of the foo command,which will be filled by "" default.
$command->option("u")->aka("username")->describedAs("Username to foo")->default("");
Then call the commandline runner with the your class:
// $class is the class that has the bar command. This will run the bar command with the optional
// parameter of "n" and needed parameters of "u" and "b".
$command->dispatchCommands($class);
The phpunit
configurations are done for this component, so you can test most of the code. You can also add your changes to the code.
SEE LICENSE and CREDIT files