Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
b73e0f7
initial commit
exonintrendo Feb 24, 2015
cf7cfb3
fixed hh extension
exonintrendo Feb 24, 2015
14d294f
initial commit
exonintrendo Feb 24, 2015
ad8e97e
fleshed out the argument parser
exonintrendo Feb 24, 2015
ced7517
added argument parsing support for flags, options, and arguments
exonintrendo Feb 25, 2015
c924552
fleshed out basic abstract command, added help screen functionality,
exonintrendo Feb 26, 2015
7b8ff19
renamed classes to make more sense (all arguments 'Arguments' is now …
exonintrendo Feb 27, 2015
617bd58
fixed most type checker issues
exonintrendo Feb 27, 2015
47171da
fixed formatting issue
exonintrendo Feb 27, 2015
dd518e8
another type checker fix
exonintrendo Feb 27, 2015
80bbd09
type checker fixes!
exonintrendo Feb 27, 2015
356dbd3
just making it more strict
exonintrendo Feb 27, 2015
a515019
started documentation, added commands to help screen
exonintrendo Feb 27, 2015
4e528ea
adjusted parser so that the first argument read in is always the command
exonintrendo Feb 28, 2015
dbbaee6
initial commit
exonintrendo Feb 28, 2015
bade068
added support for rendering tree structures
exonintrendo Feb 28, 2015
6166fdb
initial commit
exonintrendo Feb 28, 2015
5b3f66f
fixed type check errors
exonintrendo Feb 28, 2015
47934a2
user now just calls 'render' on a tree to output it, the render will…
exonintrendo Mar 1, 2015
49ee277
added support for outputingg ASCII and tab-delimited tables
exonintrendo Mar 1, 2015
229b5f4
added negative aliases to flags (i.e., --foo / --no-foo)
exonintrendo Mar 2, 2015
15653b1
adjusted styling of table output
exonintrendo Mar 2, 2015
d367e64
added documentation
exonintrendo Mar 4, 2015
a324a34
changed name of constants
exonintrendo Mar 4, 2015
65e501c
yay for documentation!
exonintrendo Mar 4, 2015
c91101f
fixed some type check issues
exonintrendo Mar 4, 2015
6ce69d2
initial commit (output-related files)
exonintrendo Mar 7, 2015
c2b21e3
we now recursively format the string to handle nested xml styles
exonintrendo Mar 7, 2015
f8985b0
initial feedback commit
exonintrendo Mar 7, 2015
b03f79b
type checker fixes
exonintrendo Mar 7, 2015
f49e02f
initial commit for user input classes
exonintrendo Mar 8, 2015
4cc138e
added 'Prompt' class, adjusted abstract method to include more functi…
exonintrendo Mar 8, 2015
5eef7ab
fixed type checker errors
exonintrendo Mar 8, 2015
286041d
added documetation, fixed some type check errors
exonintrendo Mar 8, 2015
ded2d0c
adjusted test for not initially parsing commands in the `parse` metho…
exonintrendo Mar 9, 2015
deee5e0
added more documentation
exonintrendo Mar 9, 2015
e9229e2
removed unnecessary EmptyCommandStub test class
exonintrendo Mar 9, 2015
eaf4696
added bootstrapping flags, cleaned up output of available commands in…
exonintrendo Mar 9, 2015
33e1b08
fixed type check errors, changed arguments parsed in Input class to a…
exonintrendo Mar 9, 2015
d278655
added missing docs, fixed type check errors
exonintrendo Mar 9, 2015
10b4bd4
abstracted 'type' using generics of input definitions
exonintrendo Mar 9, 2015
b6a28a8
fixed typo
exonintrendo Mar 9, 2015
c4d352d
initial commit
exonintrendo Mar 9, 2015
410724e
fixed incorrect package name (copypasta error!)
exonintrendo Mar 10, 2015
2c45d92
fixed issues per PR
exonintrendo Mar 10, 2015
249ec80
fixed bug where the input parser needs to parse for potential command…
exonintrendo Mar 10, 2015
bfc18d6
missed a delete for a test
exonintrendo Mar 10, 2015
a44fc13
fixed type errors, made adjustements per comments in PR
exonintrendo Mar 10, 2015
099bcd8
since we're not using nullable class variables, need to account for e…
exonintrendo Mar 10, 2015
239cef9
addCommand now accepts the command string name for input/output injec…
exonintrendo Mar 10, 2015
23eb04d
last commit was wrong - the CONSOLE accepts command string name, here…
exonintrendo Mar 10, 2015
b380345
fixed failing test
exonintrendo Mar 10, 2015
cd23e47
reconstructed CommandStub to be a nice demo command that is fully fun…
exonintrendo Mar 10, 2015
78b5dc4
lots of changes, see previous commit details...
exonintrendo Mar 10, 2015
9846926
moved class constants to interface
exonintrendo Mar 10, 2015
2d7f88f
composer update ran
exonintrendo Mar 11, 2015
1546bd9
fixed missing return type
exonintrendo Mar 11, 2015
72ba9da
added missing docblock
exonintrendo Mar 11, 2015
e3e9939
alias methods added to AbstractCommand for Feedback classes
exonintrendo Mar 11, 2015
f11dc7f
replaced format function with Str::insert
exonintrendo Mar 11, 2015
2c54dbf
go home whitespace, yer drunk
exonintrendo Mar 11, 2015
438f8c8
throwing exception when an option has no value
exonintrendo Mar 11, 2015
fdeba82
honoring if ANSI is supported or not
exonintrendo Mar 12, 2015
4b168bb
honoring ANSI support flags on output, altered HelpScreen to pass in …
exonintrendo Mar 12, 2015
5b5fcd6
fixed type errors, made the `Tree` class's date an alias,
exonintrendo Mar 12, 2015
0cedcb6
added some missing docs, altered some class names
exonintrendo Mar 12, 2015
a6118e2
added some missing docs, altered some class names
exonintrendo Mar 12, 2015
7974a64
initial commit - VERY rough draft
exonintrendo Mar 12, 2015
26ecae7
added support for forcing ansi output and suppressing ansi output wit…
exonintrendo Mar 12, 2015
46acae1
added menu as default execution
exonintrendo Mar 13, 2015
8d5632e
console is now integrating with the `Kernel` package, feedback classe…
exonintrendo Mar 15, 2015
987cb4f
initial commit
exonintrendo Mar 15, 2015
4fd6e70
adjusted run command so that we always return an exit code, kernel ad…
exonintrendo Mar 15, 2015
a6f4ad6
gah, missing semicolon
exonintrendo Mar 16, 2015
716e3d9
register input now clones the commands parameters and adds the inputs…
exonintrendo Mar 17, 2015
ae75ffc
added methods to overrite and set all parameter bags
exonintrendo Mar 17, 2015
ebf2da8
removed unnecessary space before message
exonintrendo Mar 18, 2015
9f5e735
renamed `Console` to `Application`
exonintrendo Mar 23, 2015
ac0d648
renamed `Console` to `Application`
exonintrendo Mar 31, 2015
b60793d
docs update
exonintrendo Mar 31, 2015
cc2fa54
updated ascii tree output appearance
exonintrendo Apr 2, 2015
874e7c0
added method to specifically render version information
exonintrendo Apr 4, 2015
6e5662e
added missing doc block
exonintrendo Apr 4, 2015
c9f5f48
Quick polish while testing.
milesj Apr 7, 2015
2487223
added doc block and removed testing code
exonintrendo Apr 7, 2015
1b48d13
removed Input/Output dependencies on the constructor
exonintrendo Apr 7, 2015
70f14bf
merged from origin
exonintrendo Apr 7, 2015
1463525
Merge branch 'master' into console-package
milesj Jun 24, 2015
0baab59
Updated composer. Added readme.
milesj Jun 24, 2015
14670d6
Updated to use individual bag classes.
milesj Jun 24, 2015
ee4ebc0
Started structuring docs.
milesj Jun 25, 2015
72ea3c7
Added the application docs.
milesj Jun 27, 2015
6130bde
Added output docs.
milesj Jun 28, 2015
4de445f
Merge branch 'master' into console-package
milesj Jun 28, 2015
5584d39
Fixed comments.
milesj Jun 28, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"src/Titon/Annotation/bootstrap.hh",
"src/Titon/Cache/bootstrap.hh",
"src/Titon/Common/bootstrap.hh",
"src/Titon/Console/bootstrap.hh",
"src/Titon/Context/bootstrap.hh",
"src/Titon/Controller/bootstrap.hh",
"src/Titon/Debug/bootstrap.hh",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions docs/en/packages/console/application.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Application #

See [`Console`](console.md) for more information on scaffolding and building applications.

The `Console` object functions as the `application` of the console package. Used in conjuction with the `Console`, it provides all necessary scaffolding and setup for building and running CLI applications.

## Construction ##

Creating an application is as simple as constructing a new `Application` object and optionally passing in `Input` and `Output` objects. If no `Input` object is passed in, a new one is constructed using the global arguments provided by the PHP/Hack language.

When used with the `Console`, the `Input` and `Output` objects will be replaced by those passed into the console's `run` method.

```hack
$app = new Console();
```

## Commands ##

Once a new application has been created, add commands by calling `addCommand` and passing in a new instance of the command itself. The `Application` object will take care of setting up and configuring the `Command` as necessary.

````hack
$app->addCommand(new MyCommand());
```

## Running the Application ##

Once all necessary commands have been added, calling `run` on the `Application` object will execute the application. Again, when used with the `Console` package, this is all handled when the `Console` itself is ran.

```hack
$app->run();
```

When executing the application from the command line, the `Application` object will handle the following situations:

* If no command is provided or the `help` flag is present, the help screen of the application will be presented listing all global flags, global options, and available commands.
* If a command is present and the `help` flag is present, the help screen of the given command will be presented listing all available options, flags, and arguments as well as the usage of the command and its description.
* If the command is present with valid parameters, the application will execute the `run` command of the `Command`.

## Automatic Setup ##

The `Console` class will automatically bootstrap and set up global parameters and output styles ready for use. The following parameters are readily available:

* --help (-h): The `help` flag to automatically render the help screen of the application or given command.
* --quiet (-q): Set the verbosity of the application to 0, suppressing all output.
* --verbose (-v) [stackable]: Set the verbosity level of the application. This is stackable, so each instance of `v` will increase the verbosity level by 1.
* --ansi: Force ANSI output
* --no-ansi: Suppress all ANSI output

The following style tags are also readily available for formatting output (see [`StyleDefinition`](style-definition.md) for more information):

* `<info>`: Green text, default background
* `<warning>`: Yellow text, default background
* `<error>`: Red text, default background
* `<exception>`: White text, red background
37 changes: 37 additions & 0 deletions docs/en/packages/console/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Commands #

A `Command` is a user-created class that handles a specific process with executed by the user from a `Console` application.

## Setup ##

A `Command` object is required to have at least 2 methods: `configure` and `run`.

The `configure` method is where the user will specify the name of the command, an optional description, and register any command-specific parameters to be used at runtime.

The `run` method is executed by the `Console` after all necessary input is processed.

```hack
class HelloWorldCommand {

public function configure() {
$this->setName("hello")->setDescription("A simple 'hello world' command!");
$this->addArgument(new Argument("name"));
}

public function run() {
if (!is_null($name = $this->getArgument('name'))) {
$this->out("Hello, $name!");
} else {
$this->out("Hello, world!");
}
}
}
```

## Accessing Parameters ##

As shown above, the `getArgument` method inside of the command returns a value as opposed to the `Input` class which returns the `Argument` object. The methods `getFlag`, `getOption`, and `getArgument`, when used inside of the `Command`, will return the value (or default) of the registered parameter. If there is a necessity to access the actual objects, these can be retrieved by calling the same commands on the class's `Input` variable.

```hack
$nameArgument = $this->input->getArgument('name');
```
15 changes: 15 additions & 0 deletions docs/en/packages/console/console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Console #

The `Console` handles bootstrapping and running the `Application` object as well as providing all functionality that the [Kernel]() package provides.

## Setup ##

Setup of a new `Console` object (new CLI applications) is very simple. Since `Console` extends `Kernel`, we are required to pass in the `Application` as well as a new pipeline. Once the `Console` is ready to be ran, an `Input` and `Output` object is also required for handling all user input from the terminal and handling formatting output.

The `Pipeline` object handles management of middleware through queue data structures providing

```hack
$app = new \Titon\Console\Application();
$kernel = new Console($app, new \Titon\Kernel\Middleware\Pipeline());
$kernel->run(new \Titon\Console\Input(), new \Titon\Console\Output());
$kernel->terminate();
17 changes: 17 additions & 0 deletions docs/en/packages/console/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Console Package #

The Console package is almost a type of framework in itself with a collection of tools to aid in the construction of command line applications as well as necessary bootstrapping for handling all input, output, and help information.

### Requirements ###

* [Titon Utility package](../packages/utility/index.md)

### Installation ###

This package can be installed with Composer using the core package.

```shell
composer require titon/console:*
```

### Documentation ###
145 changes: 145 additions & 0 deletions docs/en/packages/console/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Input #

All user input is handled by the `Input` class. This is where you define all input that is accepted in the command and/or application itself. The `Input` class also handles parsing of the input to be easily read later.

## Parameters ##

Parameters are any input given by the user into the command line application. The supported types of parameters are flags, options, arguments, and commands.

#### Description ####

The (optional) description of each parameter can also be set either in its constructor or via a `setter` method. This description is used when rendering the help screen.

```hack
$param->setDescription('This is a handy parameter!');
```

#### Aliases ####

Flags and options also support aliasing. Given the flag `--foo`, an alias assigned to it of `-f` will allow the user to retrieve the flag and assign values using either name.

```hack
$param = (new Flag('foo'))->alias('f');
```

#### Mode ####

The `mode` determines if user input is required for the paramter. If no input is given and the mode is set to be required, then an exception will be thrown.

The `mode` is set at construction or through a `setter` method. By default, all parameters are set to optional.

```hack
$param->setMode(AbstractInputDefinition::MODE_REQUIRED);
```

### Flags ###

A `Flag` is a boolean flag that is only checked by the parser for its existence. If the flag is present, it is given a value of 1 and a value of 0 is given if it is not.

**NOTE:** Although we say its a `boolean` parameter, that only means the parser does not attempt to give the parameter a value read from the user input. It only checks for the parameter's existence. The `value` assigned to flags are actually numeric to allow for stackable flags.

A flag is added to the `Input` object via the `addFlag` method.

```hack
$input->addFlag(new Flag('foo'));
```

Construction of a `Flag` is done by denoting a name for the flag, an optional description, a `mode` (if the flag is required or not), an a boolean value to determine if the flag is stackable.

```hack
$flag = new Flag('verbose', 'Set the verbosity level of the application', Flag::MODE_OPTIONAL, true);
```

A registered `Flag` object can be retrieved from the `Input` class by calling the `getFlag` method and passing in either the name or alias of the flag.

```hack
$myFlag = $input->getFlag('foo'); // Valid
$myFlag = $input->getFlag('f'); // Also valid
```

All registered flags can also be retrieved via the `getFlags` method.

#### Stackable Flags #####

If a flag is stackable, then the presence of multiple instances of the flag (consecutively) will increase the value of the flag.

```bash
-vvv // Given a value of 3
```

If the flag is not stackable, then it is either given a value of 1 (present) and 0 (if not present).

### Options ###

An `Option` is a value-based parameter that is assigned a value based on the input from the command line. The parser handles many different types of notations for reading in options:

```bash
// Long notation
--foo bar
--foo=bar
--foo="bar"

// Short notation
-f bar
-f=bar
-f="bar"
```

An option is added to the `Input` object via the `addOption` method.

```hack
$input->addOption(new Option('foo'));
```

**NOTE:** If a value containing spaces is to meant to be assigned to an option, it is required to be in quotes.

A registered `Option` object can be retrieved from the `Input` class by calling the `getOption` method and passing in either the name or alias of the option.

```hack
$myOption = $input->getOption('foo'); // Valid
$myOption = $input->getOption('f'); // Also valid
```

All registered options can also be retrieved via the `getOptions` method.

### Arguments ###

Arguments are parameters passed into the application that are not represented by any specific notation. For example, a 'hello world' application may accept a name argument and would be run as:

```hack
hhvm hello.hh "Alex Phillips"
```

An argument is added to the `Input` object via the `addArgument` method.

```hack
$input->addArgument(new Argument('foo'));
```

A registered `Argument` object can be retrieved from the `Input` class by calling the `getArgument` method and passing in the name of the argument.

```hack
$nameArgument = $input->getArgument('name');
```

All registered arguments can also be retrieved via the `getArguments` method.

## [Commands](commands.md) ##

Commands are added to the application through the `addCommand` method in the `Input` class. You can either preemptively parse a command out from the `Input` by calling `getActiveCommand`, or simply call `parse` which will parse out the command along with the rest of the registered parameters.

Once the input has been parsed, `getActiveCommand` will return whatever command has been parsed.

```hack
$input->addCommand(new MyCommand());
```

*See [Commands](commands.md) for more information.*

## User Input ##

The `Input` class also manages all user input via STDIN. This functionality is used in the [user input](user-input.md) classes for retrieving information from the user. If this functionality is needed outside of these classes, simply call `getUserInput` to prompt and return the entered value.

```hack
$usersValue = $input->getUserInput();
```
Loading