dotnet / dotnet/command-line-api

Allow adding aliases to command using object initializer

Open
#1,262 4 comments 1 reaction 0 assignees View on GitHub
Area-API enhancement
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

This is a simple example:
```cs
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.
```cs
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
new Command("qwerty")
}
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.