Skip to content

Commit fee6f46

Browse files
committed
Document the ability to set aliases and hidden status via command name
- Add separate documentation sections for command aliases and hidden commands - Document the pipe syntax to define command aliases - Document how to make commands hidden using the `|` prefix - Show examples for the #[AsCommand] attribute - Include separate version annotations for Symfony 7.4 for each feature - Ensure lines are within 80 character limit
1 parent e9f04f4 commit fee6f46

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

console.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,51 @@ 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+
use Symfony\Component\Console\Attribute\AsCommand;
247+
use Symfony\Component\Console\Command\Command;
248+
249+
#[AsCommand(
250+
name: 'app:create-user|app:add-user|app:new-user',
251+
description: 'Creates a new user.',
252+
)]
253+
class CreateUserCommand extends Command
254+
{
255+
// ...
256+
}
257+
258+
.. versionadded:: 7.4
259+
260+
The ability to define aliases through the command name was introduced in
261+
Symfony 7.4.
262+
263+
When using the pipe syntax, the first name in the list defines the command name,
264+
the others are aliases.
265+
266+
To create a hidden command, start the name with a pipe (``|``)::
267+
268+
use Symfony\Component\Console\Attribute\AsCommand;
269+
use Symfony\Component\Console\Command\Command;
270+
271+
#[AsCommand(
272+
name: '|app:create-user',
273+
description: 'Creates a new user.',
274+
)]
275+
class CreateUserCommand extends Command
276+
{
277+
// ...
278+
}
279+
280+
.. versionadded:: 7.4
281+
282+
The ability to define hidden commands through the command name was
283+
introduced in Symfony 7.4.
284+
285+
When the first name is empty (starts with ``|``), the command is marked as
286+
hidden.
287+
243288
If you can't use PHP attributes, register the command as a service and
244289
:doc:`tag it </service_container/tags>` with the ``console.command`` tag. If you're using the
245290
:ref:`default services.yaml configuration <service-container-services-load-example>`,

console/hide_commands.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,25 @@ 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+
use Symfony\Component\Console\Attribute\AsCommand;
30+
use Symfony\Component\Console\Command\Command;
31+
32+
#[AsCommand(name: '|app:legacy')]
33+
class LegacyCommand extends Command
34+
{
35+
// ...
36+
}
37+
38+
.. versionadded:: 7.4
39+
40+
The ability to define a command as hidden using the pipe syntax in the
41+
command name was introduced in Symfony 7.4.
42+
43+
Hidden commands behave the same as normal commands but they are no longer
44+
displayed in command listings, so end-users are not aware of their existence.
2845

2946
.. note::
3047

0 commit comments

Comments
 (0)