Aura.Cli help command
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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