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 all 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: 0 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Vagrant.configure("2") do |config|

# Increase memory size as HHVM requires at minimum 1GB
config.vm.provider "virtualbox" do |v|
v.name = "titon"
v.memory = 2048
v.cpus = 2
v.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"]
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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/Crypto/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.

3 changes: 2 additions & 1 deletion docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ Packages
* [Annotation](packages/annotation/index.md)
* [Cache](packages/cache/index.md)
* [Common](packages/common/index.md)
* [Console](packages/console/index.md)
* [Context](packages/context/index.md)
* [Controller](packages/controller/index.md)
* [Crypto](packages/crypto/index.md)
* [Debug](packages/debug/index.md)
* [Environment](packages/environment/index.md)
* [Environment](packages/env/index.md)
* [Event](packages/event/index.md)
* [HTTP](packages/http/index.md)
* [Intl](packages/intl/index.md)
Expand Down
94 changes: 94 additions & 0 deletions docs/en/packages/console/application.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Application #

There are two distinct parts to a console application, the first being `Titon\Console\Application`, which is the application itself. The application handles the [reading of input](input.md), [sending of output](output.md), and the [registering and running of commands](commands.md).

```hack
$app = new Titon\Console\Application();
```

An application can be customized with a name, version, and banner, all of which will be displayed when the application is ran. The banner is usually a piece of ASCII art using heredoc.

```hack
$app->setName('Titon Framework');
$app->setVersion('1.0.0');
$app->setBanner($banner);
```

The second part to a console application is the [kernel](../kernel/index.md), represented with `Titon\Console\Console`. The kernel provides a pipeline for executing middleware in the context of the command line, as well as running the application mentioned previously. The `Application` must be passed as the 1st argument.

```hack
$console = new Titon\Console\Console($app);
```

## Running & Exiting ##

Once all necessary [commands](commands.md) have been added, calling `run()` on the `Console` object will execute the application. The `run()` method requires a `Titon\Console\Input` and `Titon\Console\Output` object as arguments for handling user input from the client and formatting output.

```hack
$console->run(new Titon\Console\Input(), new Titon\Console\Output());
```

Once the application has ran, a proper exit code needs to be sent -- 0 if successful or 1 otherwise. This can be solved using the `terminate()` method.

```hack
$console->terminate();
```

### Execution Flow ###

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

* If no command is provided or the `--help` flag is present, the help screen of the application will be displayed 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 displayed 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()` method on the command.

## Parameters ##

There are 4 types of parameters, a command, arguments, flags, and options. A command must be the first parameter passed and only 1 command can be used, however, nested commands are supported. For example, if our script was named "titon.hh", and our command was named "cmd", we can do the following:

```
hhvm titon.hh cmd
```

An argument is a value passed to the command -- think method or function arguments. Multiple arguments can be passed and accessed in the order they were defined.

```
hhvm titon.hh cmd arg1 arg2 arg3
```

A flag is a boolean value that starts with a double dash (`--`), or a single dash (`-`) for its shorthand variation. The default boolean value can be reversed/negated by prepending `no-` to the flag name.

```
hhvm titon.hh cmd --flag --no-flag -f
```

And finally the option, which also starts with a double dash (`--`) and allows arbitrary values to be defined by name. There are 4 variations of options, the first with the value separated by a space, the second using an equals sign, and the last 2 wrapping the value in quotes (when special characters or spaces are used).

```
hhvm titon.hh cmd --opt1 foo --opt2=bar --opt3 "baz baz" --opt4="qux qux"
```

### Global Parameters ###

The console application will automatically bootstrap and define the following global parameters.

* `--help` (`-h`) - The help flag will display the help screen of the application or given command.
* `--quiet` (`-q`) - The quiet flag will set the verbosity of the application to 0, suppressing all output.
* `--verbose` (`-v`) The verbose flag will set the verbosity level of the application. This flag is stackable, so each instance of `v` will increase the verbosity level by 1.
* `--ansi` - The ansi flag will force ANSI output.
* `--no-ansi` - The no-ansi flag will suppress all ANSI output.

## Shebang ##

For easier use on the command line, the application file can include a shebang and drop the file extension. For example, if we have a file simply called "titon" instead of "titon.hh", we could do the following.

```
#!/usr/bin/env hhvm
<?hh
```

And then run it like so:

```
hhvm titon
```
43 changes: 43 additions & 0 deletions docs/en/packages/console/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Commands #

Instantiation and config here.

## Defining Parameters ##

### Arguments ###

### Flags ###

### Options ###

## Accepting Input ##

### Confirmations ###

confirm()

### Prompts ###

prompt()

### Menus ###

menu()

## Sending Output ##

### Messages ###

out(), error()

### Progress Bars ###

progressBar()

### Spinners ###

wait()

### Trees ###

### Tables ###
22 changes: 22 additions & 0 deletions docs/en/packages/console/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Console Package #

The Console package provides a set of tools that aid in the construction of command line applications, as well as necessary bootstrapping for handling all input and output.

### Installation ###

This package can be installed with Composer.

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

### Documentation ###

* [Application](application.md)
* [Input](input.md)
* [Output](output.md)
* [Commands](commands.md)


* [Type Aliases](types.md)

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

## Arguments ##

## Flags ##

### Negative ###

### Stackable ###

## Options ##

## Commands ##

## User Input ##
23 changes: 23 additions & 0 deletions docs/en/packages/console/old/application.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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());
```
37 changes: 37 additions & 0 deletions docs/en/packages/console/old/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');
```
Loading