Alias

It is possible to define an alias for a command. This is convenient for cases where you want to create a shorter version of a command or going through a complete command rename while keeping old one temporarily in place.

Format for alias is slighly different than a command. When command is defined as an array it’s concatenated together into a single command. When alias is defined as an array it’s used to create a separate aliases.

Aliases with a plain CommandRegistration is simple and clear as you get exactly what you define as there’s no "magic" in it.

CommandRegistration commandRegistration() {
	return CommandRegistration.builder()
		.command("mycommand")
		// define alias as myalias
		.withAlias()
			.command("myalias")
			.and()
		// define alias as myalias1 and myalias2
		.withAlias()
			.command("myalias1", "myalias2")
			.and()
		.build();
}

Defining alias with @Command annotation is a bit more involved as it can exist on a both class and method levels. Here are examples how it works.

Alias just on a method gives you myalias.

@Command
class MyCommands {

	@Command(command = "mycommand", alias = "myalias")
	void myCommand() {
	}
}

Or myalias1 and myalias2 if defined as an array.

@Command
class MyCommands {

	@Command(command = "mycommand", alias = { "myalias1", "myalias2" })
	void myCommand() {
	}
}

Alias only on a class level does nothing as it’s simply an instruction for annotation on a method level if defined.

@Command(alias = "myalias")
class MyCommands {

	@Command(command = "mycommand")
	void myCommand() {
	}
}

Alias on both class and method level combines those two together where class level works as an prefix and method level as combination of aliases. Alias on a class level is usually used together with a command prefix to keep aliases on a same command level.

Here you’d get alias myalias1 myalias2.

@Command(alias = "myalias1")
class MyCommands {

	@Command(command = "mycommand", alias = "myalias2")
	void myCommand() {
	}
}

On a method level there’s a special format, that being an empty string which allows you to create an alias but it only uses prefix from a class level.

Here you’d get alias myalias1.

@Command(command = "mycommand", alias = "myalias")
class MyCommands {

	@Command(command = "", alias = "")
	void myMainCommand() {
	}

	@Command(command = "mysubcommand", alias = "mysubalias")
	void mySubCommand() {
	}
}