1. Go to this page and download the library: Download aura/cli library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aura / cli example snippets
use Aura\Cli\CliFactory;
$cli_factory = new CliFactory;
$context = $cli_factory->newContext($GLOBALS);
$options = [
'a', // short flag -a, parameter is not allowed
'b:', // short flag -b, parameter is bar:', // long option --bar, parameter is
$a = $getopt->get('-a', false); // true if -a was passed, false if not
$b = $getopt->get('-b');
$c = $getopt->get('-c', 'default value');
$foo = $getopt->get('--foo', 0); // true if --foo was passed, false if not
$bar = $getopt->get('--bar');
$baz = $getopt->get('--baz', 'default value');
$g = $getopt->get('-g', []);
// alias -f to --foo
$options = [
'foo,f:', // long option --foo or short flag -f, parameter same values
$f = $getopt->get('-f'); // both -f and --foo have the same values
$options = [
'a',
'foo:',
];
$getopt = $context->getopt($options);
// if the script was invoked with:
// php script.php arg1 --foo=bar -a arg2
$arg0 = $getopt->get(0); // script.php
$arg1 = $getopt->get(1); // arg1
$arg2 = $getopt->get(2); // arg2
$foo = $getopt->get('--foo'); // bar
$a = $getopt->get('-a'); // 1
use Aura\Cli\CliFactory;
$cli_factory = new CliFactory;
$stdio = $cli_factory->newStdio();
// print to stdout
$stdio->outln('This is normal text.');
// print to stderr
$stdio->errln('<<red>>This is an error in red.');
$stdio->errln('Output will stay red until a formatting change.<<reset>>');
use Aura\Cli\CliFactory;
use Aura\Cli\Status;
new CliFactory;
$context = $cli_factory->newContext($GLOBALS);
$stdio = $cli_factory->newStdio();
// define options and named arguments through getopt
$options = ['verbose,v'];
$getopt = $context->getopt($options);
// do we have a name to say hello to?
$name = $getopt->get(1);
if (! $name) {
// print an error
$stdio->errln("Please give a name to say hello to.");
exit(Status::USAGE);
}
// say hello
if ($getopt->get('--verbose')) {
// verbose output
$stdio->outln("Hello {$name}, it's nice to see you!");
} else {
// plain output
$stdio->outln("Hello {$name}!");
}
// done!
exit(Status::SUCCESS);
use Aura\Cli\Help;
class MyCommandHelp extends Help
{
protected function init()
{
$this->setSummary('A single-line summary.');
$this->setUsage('<arg1> [<arg2>]');
$this->setOptions([
'f,foo' => "The -f/--foo option description.",
'bar::' => "The --bar option description.",
]);
$this->setDescr("A multi-line description of the command.");
}
}
use Aura\Cli\CliFactory;
use Aura\Cli\Context\OptionFactory;
$cli_factory = new CliFactory;
$stdio = $cli_factory->newStdio();
$help = new MyCommandHelp(new OptionFactory);
$stdio->outln($help->getHelp('my-command'));
use Aura\Cli\CliFactory;
use Aura\Cli\Context\OptionFactory;
use Aura\Cli\Help;
$cli_factory = new CliFactory;
$stdio = $cli_factory->newStdio();
$help = new Help(new OptionFactory);
$this->setSummary('A single-line summary.');
$help->setOptions([
'f,foo' => "The -f/--foo option description.",
'bar::' => "The --bar option description.",
'#arg1' => "The description for argument 1.",
'#arg2?' => "The description for argument 2.",
]);
$this->setDescr("A multi-line description of the command.");
$stdio->outln($help->getHelp('my-command'));
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.