PHP Console Kit is a simple PHP library for creating command-line applications. This library strongly inspired by Laravel Artisan Console. This project is a fork of rakit/console.
- Closure command. You don't need to create class for simple command.
- Built-in command
list. - Auto help handler for each commands.
- Easy command signature.
- Password input.
- Simple Coloring.
Install the package:
composer require michalskoula/consoleCreate a file named cli (without extension).
<?php
use MichalSkoula\Console\App;
require('vendor/autoload.php');
// 1. Initialize app
$app = new App;
// 2. Register commands
$app->command('hello {name}', 'Say hello to someone', function($name) {
$this->writeln("Hello {$name}");
});
// 3. Run app
$app->run();Open terminal/cmd, go to your app directory, run this command:
php cli hello "John Doe"
You can see available commands by typing this:
php cli list
You can show help by putting --help or -h for each command. For example:
php cli hello --help
Use groups to organize the command list. Commands are displayed in registration order.
use MichalSkoula\Console\Color;
$app->group('Maintenance', Color::RED, function () {
$this->command('maintenance:on', 'Enable maintenance mode', function () {
// ...
});
});The fourth argument of command() changes the command name color:
$app->command('danger', 'Run a dangerous command', function () {
// ...
}, Color::RED);Available foreground colors are defined as Color constants, for example Color::LIGHT_GREEN and Color::YELLOW.
Use setListHeader() to replace the default Available Commands: text. The header supports multiple lines, including ASCII art.
$app->setListHeader(<<<'HEADER'
My Console
==========
HEADER, Color::CYAN);Pass a third argument in milliseconds to display the header with a typing effect:
$app->setListHeader($asciiArt, Color::CYAN, 12);