Skip to content

Commit f5ca9c5

Browse files
OskarStarkjaviereguiluz
authored andcommitted
Document the ability to set aliases and hidden status via command name
- Add documentation for command aliases using pipe syntax in console.rst - Document how to make commands hidden using the `|` prefix in hide_commands.rst - Show examples for the #[AsCommand] attribute - Include version annotations for Symfony 7.4 - Ensure lines are within 80 character limit
1 parent 2f9c5cc commit f5ca9c5

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

console.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,33 @@ After configuring and registering the command, you can run it in the terminal:
206206
As you might expect, this command will do nothing as you didn't write any logic
207207
yet. Add your own logic inside the ``__invoke()`` method.
208208

209+
Command Aliases
210+
~~~~~~~~~~~~~~~
211+
212+
You can define alternative names (aliases) for a command directly in its name
213+
using a pipe (``|``) separator. The first name in the list becomes the actual
214+
command name; the others are aliases that can also be used to run the command::
215+
216+
// src/Command/CreateUserCommand.php
217+
namespace App\Command;
218+
219+
use Symfony\Component\Console\Attribute\AsCommand;
220+
use Symfony\Component\Console\Command\Command;
221+
222+
#[AsCommand(
223+
name: 'app:create-user|app:add-user|app:new-user',
224+
description: 'Creates a new user.',
225+
)]
226+
class CreateUserCommand extends Command
227+
{
228+
// ...
229+
}
230+
231+
.. versionadded:: 7.4
232+
233+
The ability to define aliases through the command name was introduced in
234+
Symfony 7.4.
235+
209236
Console Output
210237
--------------
211238

console/hide_commands.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,28 @@ the ``hidden`` property of the ``AsCommand`` attribute::
2222
// ...
2323
}
2424

25-
Hidden commands behave the same as normal commands but they are no longer displayed
26-
in command listings, so end-users are not aware of their existence.
25+
You can also define a command as hidden using the pipe (``|``) syntax in the
26+
command name::
27+
28+
// src/Command/LegacyCommand.php
29+
namespace App\Command;
30+
31+
use Symfony\Component\Console\Attribute\AsCommand;
32+
use Symfony\Component\Console\Command\Command;
33+
34+
#[AsCommand(name: '|app:legacy')]
35+
class LegacyCommand extends Command
36+
{
37+
// ...
38+
}
39+
40+
.. versionadded:: 7.4
41+
42+
The ability to define a command as hidden using the pipe syntax in the
43+
command name was introduced in Symfony 7.4.
44+
45+
Hidden commands behave the same as normal commands but they are no longer
46+
displayed in command listings, so end-users are not aware of their existence.
2747

2848
.. note::
2949

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy