dev-master
9999999-deva minimalistic PHP framework for rapid development of Command Line Interface tools.
MIT
The Requires
- ext-mbstring *
- php ^7.0
framework php console cli
a minimalistic PHP framework for rapid development of Command Line Interface tools.
, (*1)
a minimalistic PHP framework for rapid Command Line Interface tools development., (*2)
Tooler can be installed using Composer:, (*3)
composer create-project kovsky0/tooler-framework -s dev
The main idea behind this project was to create a minimalistic framework for rapid CLI tools development. It gives you a simple directory structure and access to basic helpers for: parsing the input, formatting the output, and prompting user for additional input., (*4)
After creating the project you can build your commands through 'tooler build' command:, (*5)
php tooler build two-plus-two
It will automatically create the following files: - ./two-plus-two which you can use to run your command with 'php two-plus-two' - ./Commands/TwoPlusTwo/TwoPlusTwoCommand.php which you can use to specify what your command should do, (*6)
!!! Imporant: for the consistant composition, please use a dash ("-") to seperate the words., (*7)
### Step 2: Define what the command should do
Add your logic to the 'execute' method in the following file:
./Commands/TwoPlusTwo/TwoPlusTwoCommand.php
For example:
```
<?php
namespace ToolerFramework\Commands\TwoPlusTwo;, (*8)
use ToolerFramework\Commands\StandardCommand;, (*9)
class TwoPlusTwoCommand extends StandardCommand { public function execute() { echo 2+2; } } ```, (*10)
### Step 3: Run your command
Run you command by typing:
php two-plus-two
, (*11)
## Basic usage, (*12)
### Available commands
You can see tooler's available commands by typing:
php tooler help
, (*13)
There are following commands available:, (*14)
php tooler build <new-command-name>
Builds new command., (*15)
php tooler rename <old-command-name> <new-command-name>
Renames the command., (*16)
php tooler remove <command-name>
Removes the command and all files associated with it., (*17)
There are 3 helpers available to you (if your command extends "StandardCommand", which is true by default)., (*18)
You can use it in your code by referencing $this->input.
- $this->input->command
- the name of the command that was called
- $this->input->flags
- all the -short and --long flags that have been used
- $this->input->arguments
- all the other arguments that have been used, (*19)
You can use it in your code by referencing $this->output.
- $this->output->write("exemplary text", "white", "red")
- outputs given text to the console, first color is a color of the fotn, second color is the color of the background.
- $this->output->writeln("exemplary text", "white", "red")
- outputs given text to the console with a newline character at the end.
- $this->output->wirteln(array("line 1", "line 2", "third line"), "white", "red")
- outputs each elements of the array in a new line
- $this->output->message("Title: ", "A long text body of the message")
- outputs multiline message, where the text is justified next to the provided title. See an example below:
TITLE: TEXT TEXT TEXT TEXT
TEXT TEXT TEXT TEXT
- $this->output->warning("This is a custom warning")
- outputs a message with "WARNING: " as a title, red background, and white font color.
- $this->output->info("This is a custom info")
- outputs a message with "INFO: " as a title, blue background, and white font color.
- $this->output->success("This is a custom success message")
- outputs a message with "SUCCESS: " as a title, green background, and white font color., (*20)
Available font colors: * 'black' * 'dark_grey' * 'blue' * 'light_blue' * 'green' * 'light_green' * 'cyan' * 'light_cyan' * 'red' * 'light_red' * 'purple' * 'light_purple' * 'brown' * 'yellow' * 'light_gray' * 'white', (*21)
Available background colors: * 'black' * 'red' * 'green' * 'yellow' * 'blue' * 'magenta' * 'cyan' * 'light_gray', (*22)
You can use it in your code by referencing $this->prompt.
- $this->prompt->prompt("What is your favourite color?")
- prompts custom text
- $this->prompt->confirm("Are you sure you want to continue? [y/n]")
- prompts a yes or no question
- $this->prompt->multipleChoice(array("blue", "yellow", "green", "red"))
- prompts a multiple choice question, by default - only one option can be chosen
- $this->prompt->multipleChoice(array("blue", "yellow", "green", "red"), null, true)
- prompts a multiple choice question, where user can choose more than one option
- $this->prompt->getResponse()
- returns the user's input
- $this->prompt->getConfirmationResponse()
- returns true for anything starting with 'y' or 'Y' and false for everything else
- $this->prompr->getMultipleChoiceResponse()
- returns user's choices for multiple choice question, (*23)
a minimalistic PHP framework for rapid development of Command Line Interface tools.
MIT
framework php console cli