Skip to content

Instantly share code, notes, and snippets.

@harikt

harikt/cli1.php Secret

Last active August 29, 2015 13:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save harikt/3b58d834edd25c02200e to your computer and use it in GitHub Desktop.
Aura.Cli help command
<?php
require dirname(__DIR__) . '/vendor/autoload.php';
use Aura\Cli\CliFactory;
$cli_factory = new CliFactory();
$context = $cli_factory->newContext($GLOBALS);
$stdio = $cli_factory->newStdio();
$options = array(
'a' => "short flag -a, parameter is not allowed",
'b:' => "short flag -b, parameter is required",
'c::' => "short flag -c, parameter is optional",
'f,foo' => "long option --foo, parameter is not allowed",
'd,doom*' => "A repeatable flag.",
'bar:' => "long option --bar, parameter is required",
'baz::' => "long option --baz, parameter is optional",
'g*::' => "short flag -g, parameter is optional, multi-pass",
);
$getopt = $context->getopt($options);
$a = $getopt->get('-a', false); // true if -a was passed, false if not
$stdio->outln("a : $a ");
$b = $getopt->get('-b');
$stdio->outln("b : $b ");
$c = $getopt->get('-c', 'default value');
$stdio->outln("c : $c ");
$foo = $getopt->get('--foo', 0); // true if --foo was passed, false if not
$stdio->outln("foo : $foo ");
$bar = $getopt->get('--bar');
$stdio->outln("bar : $bar ");
$baz = $getopt->get('--baz', 'default value');
$stdio->outln("baz : $baz ");
$g = $getopt->get('-g', []);
var_dump($g);
$help = new Aura\Cli\Help(
new Aura\Cli\Context\GetoptParser()
);
$help->setOptions($options);
$help->setSummary("Aura Help");
$help->setUsage(array(
"-a <arg1>",
"-b <arg2>"
));
$stdio->out($help->getHelp('some-fake-command'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment