Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,46 @@ Configuring the Command
You can optionally define a description, help message and the
:doc:`input options and arguments </console/input>`::

// ...
protected function configure()
{
$this
// the short description shown while running "php bin/console list"
->setDescription('Creates a new user.')
.. versionadded:: 5.3

// the full command description shown when running the command with
// the "--help" option
->setHelp('This command allows you to create a user...')
;
}
The ability to use PHP attributes to configure commands was introduced in
Symfony 5.3.

.. configuration-block::

.. code-block:: php-attributes

use Symfony\Component\Console\Attribute\ConsoleCommand

// ...

#[ConsoleCommand(
name: 'app:create-user',
description: 'Creates a new user.'
hidden: false,
aliases: ['app:new-user'],
)]

.. code-block:: php

// ...
protected function configure()
{
$this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is missing in this example

// the short description shown while running "php bin/console list"
->setDescription('Creates a new user.')

// the full command description shown when running the command with
// the "--help" option
->setHelp('This command allows you to create a user...')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please add hidden and aliases in this example too?

app::new-user could be used as an alias in both examples.

Thanks


// hidden command are not displayed while running "php bin/console list"
->setHidden(false)

->setName('app:create-user')
->setAliases(['app:new-user'])
;
}

The ``configure()`` method is called automatically at the end of the command
constructor. If your command defines its own constructor, set the properties
Expand Down Expand Up @@ -418,7 +446,7 @@ call ``setAutoExit(false)`` on it to get the command result in ``CommandTester``

$application = new Application();
$application->setAutoExit(false);

$tester = new ApplicationTester($application);

.. note::
Expand Down