@@ -147,12 +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 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
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'],
156
161
)]
157
162
class CreateUserCommand
158
163
{
@@ -162,6 +167,11 @@ You can also use ``#[AsCommand]`` to add a description and longer help text for
162
167
}
163
168
}
164
169
170
+ .. versionadded :: 7.4
171
+
172
+ The feature to define usage examples in the ``#[AsCommand] `` attribute was
173
+ introduced in Symfony 7.4.
174
+
165
175
Additionally, you can extend the :class: `Symfony\\ Component\\ Console\\ Command\\ Command ` class to
166
176
leverage advanced features like lifecycle hooks (e.g. :method: `Symfony\\ Component\\ Console\\ Command\\ Command::initialize ` and
167
177
and :method: `Symfony\\ Component\\ Console\\ Command\\ Command::interact `)::
0 commit comments