dotnet / dotnet/command-line-api

Consider using Option<T> in tutorial

Open
#803 0 comments 1 reaction 0 assignees View on GitHub
Area-Documentation
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

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.