Skip to content

[Console] Document the ability to set aliases and hidden status via command name #21166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,33 @@ After configuring and registering the command, you can run it in the terminal:
As you might expect, this command will do nothing as you didn't write any logic
yet. Add your own logic inside the ``__invoke()`` method.

Command Aliases
~~~~~~~~~~~~~~~

You can define alternative names (aliases) for a command directly in its name
using a pipe (``|``) separator. The first name in the list becomes the actual
command name; the others are aliases that can also be used to run the command::

// src/Command/CreateUserCommand.php
namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

#[AsCommand(
name: 'app:create-user|app:add-user|app:new-user',
description: 'Creates a new user.',
)]
class CreateUserCommand extends Command
{
// ...
}

.. versionadded:: 7.4

The ability to define aliases through the command name was introduced in
Symfony 7.4.

Console Output
--------------

Expand Down
24 changes: 22 additions & 2 deletions console/hide_commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,28 @@ the ``hidden`` property of the ``AsCommand`` attribute::
// ...
}

Hidden commands behave the same as normal commands but they are no longer displayed
in command listings, so end-users are not aware of their existence.
You can also define a command as hidden using the pipe (``|``) syntax in the
command name::

// src/Command/LegacyCommand.php
namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;

#[AsCommand(name: '|app:legacy')]
class LegacyCommand extends Command
{
// ...
}

.. versionadded:: 7.4

The ability to define a command as hidden using the pipe syntax in the
command name was introduced in Symfony 7.4.

Hidden commands behave the same as normal commands but they are no longer
displayed in command listings, so end-users are not aware of their existence.

.. note::

Expand Down