@@ -79,18 +79,46 @@ Configuring the Command
7979You can optionally define a description, help message and the
8080:doc: `input options and arguments </console/input >`::
8181
82- // ...
83- protected function configure()
84- {
85- $this
86- // the short description shown while running "php bin/console list"
87- ->setDescription('Creates a new user.')
82+ .. versionadded :: 5.3
8883
89- // the full command description shown when running the command with
90- // the "--help" option
91- ->setHelp('This command allows you to create a user...')
92- ;
93- }
84+ The ability to use PHP attributes to configure commands was introduced in
85+ Symfony 5.3.
86+
87+ .. configuration-block ::
88+
89+ .. code-block :: php-attributes
90+
91+ use Symfony\Component\Console\Attribute\ConsoleCommand
92+
93+ // ...
94+
95+ #[ConsoleCommand(
96+ name: 'app:create-user',
97+ description: 'Creates a new user.'
98+ hidden: false,
99+ aliases: ['app:new-user'],
100+ )]
101+
102+ .. code-block :: php
103+
104+ // ...
105+ protected function configure()
106+ {
107+ $this
108+ // the short description shown while running "php bin/console list"
109+ ->setDescription('Creates a new user.')
110+
111+ // the full command description shown when running the command with
112+ // the "--help" option
113+ ->setHelp('This command allows you to create a user...')
114+
115+ // hidden command are not displayed while running "php bin/console list"
116+ ->setHidden(false)
117+
118+ ->setName('app:create-user')
119+ ->setAliases(['app:new-user'])
120+ ;
121+ }
94122
95123 The ``configure() `` method is called automatically at the end of the command
96124constructor. If your command defines its own constructor, set the properties
@@ -418,7 +446,7 @@ call ``setAutoExit(false)`` on it to get the command result in ``CommandTester``
418446
419447 $application = new Application();
420448 $application->setAutoExit(false);
421-
449+
422450 $tester = new ApplicationTester($application);
423451
424452.. note ::
0 commit comments