feat: add support for command name aliases#10289
Open
paulbalandan wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Modern commands (
AbstractCommand+#[Command]) can now declare one or more aliases through a newaliaseslist on the#[Command]attribute. An alias is an alternative name the same command can be invoked by, useful for short forms or for renames that keep the old name working.#[Command( name: 'app:deploy', description: 'Deploys the application.', group: 'App', aliases: ['app:ship', 'deploy'], )] class AppDeploy extends AbstractCommand { /* ... */ }All of these then reach the same command:
What changed
#[Command]): thealiasesparameter takes a list of strings. Each alias is validated with the same rules asname(non-empty, no whitespace, optionally colon-namespaced, no leading/trailing/consecutive colons), must differ from the command name, and must be unique within the command. Invalid aliases are reported at discovery, the same way an invalid name already is.Commands): aliases are kept in analias => canonical namemap and resolved at lookup. The real command name is always checked first, so an alias can never shadow a command.getCommand(),verifyCommand(), andhasModernCommand()all resolve aliases, sophp spark <alias>,command('<alias>'), andservice('commands')->runCommand('<alias>', ...)all work.help <command>gains anAliases:section, andhelp <alias>resolves to the canonical command (its usage line still shows the canonical name).spark listrenders each alias as its own row marked[alias of <command>], sorted within the command's group.list --simpleincludes alias names too, since they are invokable.AbstractCommand::getAliases()andCommands::getCommandAliases().Sample
listoutput:Notes
BaseCommandcommands are unchanged.Console::getCommand()still returns the raw token the user typed (the alias), which is what logging and inspection want.Commands.invalidCommandAlias,Commands.commandAliasSameAsName,Commands.duplicateCommandAlias,Commands.aliasClashesWithCommandName,Commands.aliasClashesWithAlias,CLI.commandAlias, andCLI.helpAliases.Checklist: