https://github.com/othercodes/cli
Basic structure to develop CLI commands.
https://github.com/othercodes/cli
Last synced: 9 months ago
JSON representation
Basic structure to develop CLI commands.
- Host: GitHub
- URL: https://github.com/othercodes/cli
- Owner: othercodes
- License: mit
- Created: 2016-10-24T16:37:00.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T20:43:33.000Z (about 5 years ago)
- Last Synced: 2025-03-17T21:56:38.024Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Command Line Framework
Small command line framework to build multi-level chained commands. Offer a small writter and formatter system to print
messages with custom format (colors and style like bold or underline).
## Requirements
* PHP >= 5.4.*
* PHP Readline extension
## Usage
First we need to create an application: `\App\CLIApplication.php`
```
'Sample\App\Commands\HelloCommand',
);
/**
* Display a description message
* @return string
*/
public function description()
{
return "Sample CLI Application.";
}
}
```
Nex we create the entry point: `\app.php`
```
bootstrap($argv);
$app->execute();
```
Finally we can add all the sub-commands we want, for example:
```
writter->info('Hello World Info');
$this->writter->input("do yo like it?", 'n', true);
}
}
```
Our main code is located in the `run()` method, we also can put some code into `initialize()` and `finish()` methods. the
`initialize()` method is executed before the `run()` method, and the `finish()` method is executed after the run method.
The output of the `run()` is passed to the child command so we can use it as argument. Finally the output of the child command is
passed again to the parent command in the `finish()` method.
The only required method top execute a command is `run()`.
Its time to run the command:
```
$ php app.php
Sample CLI Application.
SampleCLIApplication v1.0.0
Options:
-h|help Show help information.
Commands:
hello Say hello world!
```
Running the sub-command.
```
$ php app.php hello
Hello World Info
do yo like it? [n]: yes
```