PHP 7.4 to 8.4 · No dependency · Any framework

Your CLI commands, one class each.

Implement one interface, declare your arguments and options, register the command. Help, validation, colors, tables and prompts come with it. Nothing else to install.

How it works

Write. Register. Run.

Three steps, and bin/console knows your command.

1. Write

A class that implements CommandInterface: a name, a description, its arguments and options, and execute().

2. Register

new CommandRunner([new SendEmailCommand()]) in your bin/console script, or from your container.

3. Run

bin/console send-email john@example.com -s Hello. Missing argument, unknown option: a clear error and a precise exit code.

What your users see:

terminal

$ bin/console send-email
[ERROR] Argument "recipient" is required for command "send-email".
$ echo $?
11
$ bin/console send-email john@example.com --subject="Meeting"
Email sent to john@example.com: Meeting

Why Console

Small enough to read in one sitting.

A dozen classes, no magic. You can open any of them and see what happens to your argv.

No dependency

Pure PHP with the mbstring, json and ctype extensions. Nothing else in your vendor/.

Any framework

Symfony, Laravel, Slim or none: build the CommandRunner yourself or take it from your container.

Help for free

bin/console lists your commands, --help describes one. Type c:c for cache:clear.

Output that behaves

Messages, tables, lists, progress bars and prompts. Errors go to STDERR, colors turn off in files and pipes.

Compare

Between $argv by hand and a full console component.

Reading $argv yourself works until the third option. A full component brings events, styles and helpers you may never use.

$argv by handsymfony/consolemichel/console
Arguments and optionsParsed by youDeclared, validatedDeclared, validated
Help and command listWritten by youYesYes
Tables, progress bars, promptsNoYes, many helpersYes, one ConsoleOutput class
Events, lazy commands, completionNoYesNo, by design
DependenciesNoneSeveral Symfony packagesNone

Scope

What Console will never do

One job: turn a command line into a call to your code.

  • add a dependency
  • require a framework
  • scan your folders for commands
  • dispatch events
  • need a configuration file

Get Console

One Composer command.

Works with PHP 7.4 to 8.4. PaperORM uses it for its migration and database commands.

$ composer require michel/console