dotnet / dotnet/command-line-api
Consider using Option<T> in tutorial
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
As a new-comer to this library I find the first example in the tutorial a bit confusing. The fact that RootCommand is an enumerable is not immediately obvious, and there are way too many `{}` for my taste.
I think it would be nice to use `Option` in the tutorial, and writing the output in one line which gets rid of most of the noise:
```cs
var command = new RootCommand
{
new Option("--a-string"),
new Option("--an-int"),
};
command.Handler = CommandHandler.Create((string aString, int anInt) =>
Console.WriteLine($"aString: {aString}, anInt: {anInt}"));
await command.InvokeAsync("--a-string \"Hello world!\" --an-int 123");
```
vs.
```cs
var command = new RootCommand
{
new Option("--a-string") { Argument = new Argument() },
new Option("--an-int") { Argument = new Argument() }
};
command.Handler = CommandHandler.Create(
(string aString, int anInt) =>
{
Console.WriteLine($"{aString}");
Console.WriteLine($"{anInt}");
});
await command.InvokeAsync("--an-int 123 --a-string \"Hello world!\" ");
Contributor guide
Assessment
This issue has not been assessed yet.