Skip to content
Muhammet Şafak edited this page May 29, 2026 · 2 revisions

InitPHP Console — Wiki

Welcome to the official documentation for initphp/console — a small, dependency-free toolkit for writing command-line applications in PHP: command routing, typed arguments, coloured output, interactive prompts, and a styleable ANSI table renderer.

composer require initphp/console
#!/usr/bin/env php<?phprequire__DIR__ . '/vendor/autoload.php';
useInitPHP\Console\{Application, Input, Output};
$console = newApplication('Acme CLI', '1.0.0');
$console->register('greet', function (Input$input, Output$output) {
$output->writeln('Hello {name}!', ['name' => $input->getArgument('name', 'World')]);
}, 'Greets someone.');
$console->run();
php console.php greet --name=Ada # Hello Ada!
php console.php list # Overview of all commands

The building blocks

TypePurpose
ApplicationThe command registry and dispatcher.
CommandBase class for class-based commands.
Input / InputInterfaceParsed access to arguments, options and segments.
InputArgumentA typed, validated --name argument declaration.
Output / OutputInterfaceColoured writing, lists, progress bar and prompts.
QuestionA value object describing an interactive question.
HelpersScalar value casting shared across the components.
Utils\TableA styleable, multibyte-aware ASCII/ANSI table renderer.

Start here

A note on terminology

This library splits the tokens after the command name into three buckets:

TokenShapeAccessor
Argument--name, --name=valuegetArgument()
Option-v, -abc, -key=valuegetOption()
Segmentbare value, e.g. migrategetSegment()

Here --long tokens are called arguments and -short tokens are called options — the opposite of some other CLI frameworks. Keep it in mind when porting code. See Input for the full grammar.

Package metadata

Since 2.1 this package also ships the table renderer formerly distributed as initphp/cli-table (now deprecated). The old class name keeps working via a class_alias — see Migration Guide.

If something in this wiki is unclear, ambiguous, or wrong, please open an issue — documentation fixes are reviewed eagerly.

Clone this wiki locally