@@ -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 >`,
148148this 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+
165175Additionally, you can extend the :class: `Symfony\\ Component\\ Console\\ Command\\ Command ` class to
166176leverage advanced features like lifecycle hooks (e.g. :method: `Symfony\\ Component\\ Console\\ Command\\ Command::initialize ` and
167177and :method: `Symfony\\ Component\\ Console\\ Command\\ Command::interact `)::
0 commit comments