Using Console Commands, Shortcuts and Built-in Commands
Warning: You are browsing the documentation for Symfony 6.3, which is no longer maintained.
Read the updated version of this page for Symfony 7.3 (the current stable version).
In addition to the options you specify for your commands, there are some built-in options as well as a couple of built-in commands for the Console component.
Note
These examples assume you have added a file application.php to run at
the CLI:
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/env php
<?php
// application.php
require __DIR__.'/vendor/autoload.php';
use Symfony\Component\Console\Application;
$application = new Application();
// ...
$application->run();Built-in Commands
There is a built-in command list which outputs all the standard options
and the registered commands:
1
$ php application.php listYou can get the same output by not running any command as well
1
$ php application.phpThe help command lists the help information for the specified command. For
example, to get the help for the list command:
1
$ php application.php help listRunning help without specifying a command will list the global options:
1
$ php application.php helpGlobal Options
You can get help information for any command with the --help option. To
get help for the list command:
1 2
$ php application.php list --help
$ php application.php list -hYou can suppress output with:
1 2
$ php application.php list --quiet
$ php application.php list -qYou can get more verbose messages (if this is supported for a command) with:
1 2
$ php application.php list --verbose
$ php application.php list -vTo output even more verbose messages you can use these options:
1 2
$ php application.php list -vv
$ php application.php list -vvvIf you set the optional arguments to give your application a name and version:
1
$application = new Application('Acme Console Application', '1.2');then you can use:
1 2
$ php application.php list --version
$ php application.php list -Vto get this information output:
1
Acme Console Application version 1.2If you do not provide a console name then it will just output:
1
console toolYou can force turning on ANSI output coloring with:
1
$ php application.php list --ansior turn it off with:
1
$ php application.php list --no-ansiYou can suppress any interactive questions from the command you are running with:
1 2
$ php application.php list --no-interaction
$ php application.php list -nShortcut Syntax
You do not have to type out the full command names. You can just type the
shortest unambiguous name to run a command. So if there are non-clashing
commands, then you can run help like this:
1
$ php application.php hIf you have commands using : to namespace commands then you only need
to type the shortest unambiguous text for each part. If you have created the
demo:greet as shown in The Console Component then you
can run it with:
1 2 3 4 5 6
$ php application.php d:g Fabien
# as long as it's unambiguous, you can also mix upper and lower case
# php application.php Demo:g Fabien
# php application.php de:Gr Fabien
# php application.php DE:Gre FabienIf you enter a short command that's ambiguous (i.e. there are more than one command that match), then no command will be run and some suggestions of the possible commands to choose from will be output.