Allow adding aliases to command using object initializer
This is a simple example:
var rootCommand = new RootCommand
{
new Command("do-something")
{
new Command("abcdefg") // How to add aliases here?
new Command("qwerty")
}
};
In this case, you have to give up using the object initializer and manually add the commands. This supposed example demonstrates an easy way to build commands.
var rootCommand = new RootCommand
{
new Command("do-something")
{
new Command("abcdefg") { Aliases = { "c", "w" } } // In reality, this will raise a compiler error, because Aliases is a IReadOnlyList<string>
new Command("qwerty")
}
};
Just an additional note: If the public API of Command is being updated/changed to allow such functionality, please also make it consistent with Option/Option<T>. Currently, Option/Option<T> allows specifying aliases through constructor arguments and an AddAlias method, whereas a Command exposes the same feature only through an AddAlias method.
Just an additional note: If the public API of
Commandis being updated/changed to allow such functionality, please also make it consistent withOption/Option<T>. Currently,Option/Option<T>allows specifying aliases through constructor arguments and anAddAliasmethod, whereas aCommandexposes the same feature only through anAddAliasmethod.
Agreed. More generally, the whole construction of the command structure should be able to be done in one go by the object initializer.
The whole pack, Option/Argument/Command should probably be changed to records so this all comes mostly for free :)
Would also be great if we can use the .AddAlias() in a fluent way. new Command() .AddAlias() .AddAlias();