Skip to content

Consider using Option<T> in tutorial #803

Open
@nohwnd

Description

@nohwnd

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<T> in the tutorial, and writing the output in one line which gets rid of most of the noise:

var command = new RootCommand
    {
        new Option<string>("--a-string"),
        new Option<int>("--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.

var command = new RootCommand
            {
                new Option("--a-string") { Argument = new Argument<string>() },
                new Option("--an-int") { Argument = new Argument<int>() }
            };

command.Handler = CommandHandler.Create(
    (string aString, int anInt) =>
    {
        Console.WriteLine($"{aString}");
        Console.WriteLine($"{anInt}");
    });

await command.InvokeAsync("--an-int 123 --a-string \"Hello world!\" ");

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions