ConsoleAppFramework icon indicating copy to clipboard operation
ConsoleAppFramework copied to clipboard

Alias Commands

Open BlackPhlox opened this issue 1 year ago • 4 comments

Alias is a great feature for options, so it goes without saying that commands should also be able to. Here's my rendition for how it could look like syntax-wise (based on Cocona):

// Program.cs
var app = ConsoleApp.Create();
app.Add<KeyVaultCommands>("KeyVault").Alias("kv");
app.Run(args);

Produces result, uses , the same as option aliases:

> MyCLI.exe
Usage: [command] [-h|--help] [--version]

Commands:
  keyvault, kv        KeyVault - Manage Azure Key Vault Secrets

Instead of Alias method, as it would have to change Add to not return void, you could also use params to take as Add argument, ie. params string[], but will then not work for the overload, when using a delegate after commandPath:

app.Add<KeyVaultCommands>("KeyVault", "kv");

BlackPhlox avatar Jun 15 '24 21:06 BlackPhlox

How common are command aliases? I feel that command aliases are close to being a bad practice, so I'm hesitant to include them. If you could provide some examples showing that they are common and beneficial, I would be willing to reconsider my stance.

neuecc avatar Jun 16 '24 15:06 neuecc

It's not common but I see it as being comparable to the shorthands that are usually available with options like: -e | --environment. I'm currently dogfooding changes in my fork, creating a new internal CLI, and I use the alias kv for keyvault, af for azure function etc. as I frequently use those commands a lot and prefer not typing them out. Though you would then properly ask, why not just always have the shorthand command name instead? This is a valid question, though the reason is that I want the full name as well for clarity and not need to have an explanation in the description of the command, which could be used for a more specific message about the command.

Also, note that the way it is currently implemented in #125, is so that it is an optional feature that should not get in the way of the current behavior. However, I haven't benchmarked the performance of the changes.

BlackPhlox avatar Jun 16 '24 19:06 BlackPhlox

Thanks. I also saw the PR. I know only a few will use this feature, but I'm OK with the introduction as it does no harm to the general use case.

neuecc avatar Jun 18 '24 10:06 neuecc

Rust's cargo command has command alias.

image

neuecc avatar Jul 24 '24 11:07 neuecc

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jan 21 '25 00:01 github-actions[bot]

v5.7.7 support it.

neuecc avatar Nov 17 '25 08:11 neuecc