GithubHelp home page GithubHelp logo

azjezz / hh-clilib Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hhvm/hh-clilib

0.0 3.0 0.0 173 KB

Command Line Interface (CLI) Library for the Hack programming language

License: MIT License

Shell 0.32% Hack 99.68%

hh-clilib's Introduction

Build Status

Hack CLI Library

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.

hh-clilib's People

Contributors

fredemmott avatar joelmarcey avatar kmeht avatar yurybandarchuk16 avatar

Watchers

James Cloos avatar Saif Eddin Gmati avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.