facebook / hh-clilib
Installs: 726 898
Dependents: 15
Suggesters: 0
Security: 0
Stars: 8
Watchers: 21
Forks: 11
Open Issues: 3
Language:Hack
Requires
- hhvm: ^4.76
- hhvm/hsl: ^4.0
- hhvm/hsl-experimental: ^4.58.0rc1
- hhvm/hsl-io: ^0.3.0
- hhvm/type-assert: ^4.0
Requires (Dev)
- facebook/fbexpect: ^2.6.1
- hhvm/hacktest: ^2.2.0rc1
- hhvm/hhvm-autoload: ^3.1.0
README
This library provides basic command-line handling, including:
- parsing of
ARGV
- interactive TTY detection
- color TTY detection
It aims for as much code as possible to be in strict mode.
Installation
hhvm composer.phar require facebook/hh-clilib
Examples
In src/MyCLI.hh
:
// MyCLI.hh <?hh // strict use type Facebook\CLILib\CLIBase; final class MyCLI extends CLIBase { <<__Override>> public async function mainAsync(): Awaitable<int> { $this->getStdout()->write("Hello, world!"); return 0; } }
In bin/mycli
:
<?hh // not strict because of top-level statements. require_once(__DIR__.'/../vendor/hh_autoload.php'); MyCLI::main();
Options
Options are optional, always have a long form (e.g. --foo
), may have a short form (e.g. -f
), and may
require a value (e.g. --foo=bar
or --foo bar
).
You can specify supported options by implemented getSupportedOptions()
; --help
is always supported.
<<__Override>> protected function getSupportedOptions(): vec<CLIOptions\CLIOption> { return vec[ CLIOptions\flag( () ==> { $this->verbosity++; }, "Increase output verbosity", '--verbose', '-v', ), CLIOptions\with_required_enum( OutputFormat::class, $f ==> { $this->format = $f; }, Str\format( "Desired output format (%s). Default: %s", Str\join(OutputFormat::getValues(), '|'), (string) $this->format, ), '--format', '-f', ), CLIOptions\with_required_string( $s ==> { $this->outputRoot = $s; }, "Directory for output files. Default: working directory", '--output', '-o', ), ]; }
Arguments
Arguments do not have a name, and may be required. To support arguments, extend CLIWithArguments
or CLIWithRequiredArguments
.
Arguments are always strings, and can be retrieved via ->getArguments();
Contributing
See CONTRIBUTING.md.
License
hh-clilib is MIT-licensed.