@@ -147,13 +147,17 @@ If you can't use PHP attributes, register the command as a service and
147
147
:ref: `default services.yaml configuration <service-container-services-load-example >`,
148
148
this is already done for you, thanks to :ref: `autoconfiguration <services-autoconfigure >`.
149
149
150
- You can also use ``#[AsCommand] `` to add a description, usages, 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::
151
152
152
153
#[AsCommand(
153
154
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
156
- usages: ['app:create-user alice'],
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'],
157
161
)]
158
162
class CreateUserCommand
159
163
{
@@ -165,7 +169,8 @@ You can also use ``#[AsCommand]`` to add a description, usages, and longer help
165
169
166
170
.. versionadded :: 7.4
167
171
168
- The ability to add usages via a ``$usages `` property was introduced in Symfony 7.4.
172
+ The feature to define usage examples in the ``#[AsCommand] `` attribute was
173
+ introduced in Symfony 7.4.
169
174
170
175
Additionally, you can extend the :class: `Symfony\\ Component\\ Console\\ Command\\ Command ` class to
171
176
leverage advanced features like lifecycle hooks (e.g. :method: `Symfony\\ Component\\ Console\\ Command\\ Command::initialize ` and
0 commit comments