Skip to content

Commit f43fce5

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 f43fce5

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

console.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,57 @@ 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+
269+
To create a hidden command, start the name with a pipe (``|``)::
270+
271+
// src/Command/CreateUserCommand.php
272+
namespace App\Command;
273+
274+
use Symfony\Component\Console\Attribute\AsCommand;
275+
use Symfony\Component\Console\Command\Command;
276+
277+
#[AsCommand(
278+
name: '|app:create-user',
279+
description: 'Creates a new user.',
280+
)]
281+
class CreateUserCommand extends Command
282+
{
283+
// ...
284+
}
285+
286+
.. versionadded:: 7.4
287+
288+
The ability to define hidden commands through the command name was
289+
introduced in Symfony 7.4.
290+
291+
When the first name is empty (starts with ``|``), the command is marked as
292+
hidden.
293+
243294
If you can't use PHP attributes, register the command as a service and
244295
:doc:`tag it </service_container/tags>` with the ``console.command`` tag. If you're using the
245296
: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)