Symfony
sponsored by SensioLabs
Menu
  • About
  • Documentation
  • Screencasts
  • Cloud
  • Certification
  • Community
  • Businesses
  • News
  • Download
  1. Home
  2. Documentation
  3. Components
  4. Console
  5. Using Console Commands, Shortcuts and Built-in Commands
  • Documentation
  • Book
  • Reference
  • Bundles
  • Cloud
Search by Algolia

Table of Contents

  • Built-in Commands
  • Global Options
  • Shortcut Syntax

Using Console Commands, Shortcuts and Built-in Commands

Edit this page

Warning: You are browsing the documentation for Symfony 2.0, which is no longer maintained.

Read the updated version of this page for Symfony 6.2 (the current stable version).

Using Console Commands, Shortcuts and Built-in Commands

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 app/console to run at the cli:

1
2
3
4
5
6
7
8
9
#!/usr/bin/env php
# app/console
<?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 app/console list

You can get the same output by not running any command as well

1
$ php app/console

The help command lists the help information for the specified command. For example, to get the help for the list command:

1
$ php app/console help list

Running help without specifying a command will list the global options:

1
$ php app/console help

Global Options

You can get help information for any command with the --help option. To get help for the list command:

1
2
$ php app/console list --help
$ php app/console list -h

You can suppress output with:

1
2
$ php app/console list --quiet
$ php app/console list -q

You can get more verbose messages (if this is supported for a command) with:

1
2
$ php app/console list --verbose
$ php app/console list -v

If 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 app/console list --version
$ php app/console list -V

to get this information output:

1
Acme Console Application version 1.2

If you do not provide both arguments then it will just output:

1
console tool

You can force turning on ANSI output coloring with:

1
$ php app/console list --ansi

or turn it off with:

1
$ php app/console list --no-ansi

You can suppress any interactive questions from the command you are running with:

1
2
$ php app/console list --no-interaction
$ php app/console list -n

Shortcut 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 app/console h

If you have commands using : to namespace commands then you just have 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
$ php app/console d:g Fabien

If 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.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
We stand with Ukraine.
Version:
Put the code quality back at the heart of your project

Put the code quality back at the heart of your project

Peruse our complete Symfony & PHP solutions catalog for your web development needs.

Peruse our complete Symfony & PHP solutions catalog for your web development needs.

↓ Our footer now uses the colors of the Ukrainian flag because Symfony stands with the people of Ukraine.

Avatar of Andrey Lukin, a Symfony contributor

Thanks Andrey Lukin (@wtorsi) for being a Symfony contributor

1 commit • 4 lines changed

View all contributors that help us make Symfony

Become a Symfony contributor

Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

Learn how to contribute

Symfony™ is a trademark of Symfony SAS. All rights reserved.

  • What is Symfony?
    • Symfony at a Glance
    • Symfony Components
    • Case Studies
    • Symfony Releases
    • Security Policy
    • Logo & Screenshots
    • Trademark & Licenses
    • symfony1 Legacy
  • Learn Symfony
    • Symfony Docs
    • Symfony Book
    • Reference
    • Bundles
    • Best Practices
    • Training
    • eLearning Platform
    • Certification
  • Screencasts
    • Learn Symfony
    • Learn PHP
    • Learn JavaScript
    • Learn Drupal
    • Learn RESTful APIs
  • Community
    • SymfonyConnect
    • Support
    • How to be Involved
    • Code of Conduct
    • Events & Meetups
    • Projects using Symfony
    • Downloads Stats
    • Contributors
    • Backers
  • Blog
    • Events & Meetups
    • A week of symfony
    • Case studies
    • Cloud
    • Community
    • Conferences
    • Diversity
    • Documentation
    • Living on the edge
    • Releases
    • Security Advisories
    • SymfonyInsight
    • Twig
    • SensioLabs
  • Services
    • SensioLabs services
    • Train developers
    • Manage your project quality
    • Improve your project performance
    • Host Symfony projects
    Deployed on
Follow Symfony
Search by Algolia