Skip to content

Latest commit

 

History

49 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

.NET 10 GitHub License GitHub Release

System.CommandLine.Extensions

The new System.CommandLine API offers for sure more advanced command configuration and execution than the retired Microsoft.Extensions.CommandLineUtils API. But the broader set of functionality comes with the burden of more complex boilerplate code required to let the cow fly. The System.CommandLine.Extensions API adds a thin application layer to System.CommandLine which is similar to the retired API, cuts down functionality and thus brings back the simplicity.

Features

  • Fluent API: Easy command and option configuration.
  • Async Support: Full support for asynchronous command handlers.
  • Source Generation: Automated binding of command line options to handler parameters.
  • POSIX-compliant: Support for standard command-line argument bundling.

Greeting Example

using System.CommandLine;
using System.CommandLine.Extensions;

var app = new CommandLineApplication();

app.Command("greeting", "Greets the specified person.", greeting =>
{
    greeting.Option<string>("--name", "The person's name.", ArgumentArity.ExactlyOne)
        .Option<bool>("--polite")
        .OnExecute(async (string name, bool polite) =>
        {
            Console.WriteLine(polite ? $"Good day {name}" : $"Hello {name}");
            return await Task.FromResult(0);
        });
});

return await app.ExecuteAsync(args);

Usage

$ demo greeting --name John --polite
Good day John

Releases

Used by

Contributors

Languages