Skip to content

Commit 916621f

Browse files
committed
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 e9f04f4 commit 916621f

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

console.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,32 @@ You can register the command by adding the ``AsCommand`` attribute to it::
240240
// ...
241241
}
242242

243+
You can also define aliases directly in the command name using a pipe (``|``)
244+
separator::
245+
246+
// src/Command/CreateUserCommand.php
247+
namespace App\Command;
248+
249+
use Symfony\Component\Console\Attribute\AsCommand;
250+
use Symfony\Component\Console\Command\Command;
251+
252+
#[AsCommand(
253+
name: 'app:create-user|app:add-user|app:new-user',
254+
description: 'Creates a new user.',
255+
)]
256+
class CreateUserCommand extends Command
257+
{
258+
// ...
259+
}
260+
261+
.. versionadded:: 7.4
262+
263+
The ability to define aliases through the command name was introduced in
264+
Symfony 7.4.
265+
266+
When using the pipe syntax, the first name in the list defines the command name,
267+
the others are aliases.
268+
243269
If you can't use PHP attributes, register the command as a service and
244270
:doc:`tag it </service_container/tags>` with the ``console.command`` tag. If you're using the
245271
:ref:`default services.yaml configuration <service-container-services-load-example>`,

console/hide_commands.rst

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

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

2949
.. note::
3050

0 commit comments

Comments
 (0)