Skip to content

Commit 96deeec

Browse files
committed
Merge branch '7.4' into 8.0
* 7.4: Tweaks Document that usages may be supplied by AsCommand Attribute
2 parents 55f21cf + f9e1b89 commit 96deeec

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

console.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,17 @@ If you can't use PHP attributes, register the command as a service and
147147
:ref:`default services.yaml configuration <service-container-services-load-example>`,
148148
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
149149

150-
You can also use ``#[AsCommand]`` to add a description and longer help text for the command::
150+
You can also use ``#[AsCommand]`` to add a description, usage exampless, and
151+
longer help text for the command::
151152

152153
#[AsCommand(
153154
name: 'app:create-user',
154-
description: 'Creates a new user.', // the command description shown when running "php bin/console list"
155-
help: 'This command allows you to create a user...', // the command help shown when running the command with the "--help" option
155+
// this short description is shown when running "php bin/console list"
156+
description: 'Creates a new user.',
157+
// this is shown when running the command with the "--help" option
158+
help: 'This command allows you to create a user...',
159+
// this allows you to show one or more usage examples (no need to add the command name)
160+
usages: ['bob', 'alice --as-admin'],
156161
)]
157162
class CreateUserCommand
158163
{
@@ -162,6 +167,11 @@ You can also use ``#[AsCommand]`` to add a description and longer help text for
162167
}
163168
}
164169

170+
.. versionadded:: 7.4
171+
172+
The feature to define usage examples in the ``#[AsCommand]`` attribute was
173+
introduced in Symfony 7.4.
174+
165175
Additionally, you can extend the :class:`Symfony\\Component\\Console\\Command\\Command` class to
166176
leverage advanced features like lifecycle hooks (e.g. :method:`Symfony\\Component\\Console\\Command\\Command::initialize` and
167177
and :method:`Symfony\\Component\\Console\\Command\\Command::interact`)::

0 commit comments

Comments
 (0)