dotnet / dotnet/command-line-api
Suggestion: what about a minimal API like configuration?
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
this is a suggestion! But with some minimal set of extensions, I could use your library and produce a setup like this. The only difference or caveat compared with the host builder extensions/setup you already have, is that the setup/command builder will not filter out the argument it has mapped, before passing it to the host builder. But for me, this was no issue. Let me know what you think. This is just a suggestion, no critique on the great work the team is delivering.
```
var builder = Host.CreateDefaultBuilder(args)
.ConfigureServices((c, s) => s.AddYourServicesHere(c));
var app = builder.Build();
await app.AddCommandLine(builder => builder
.AddCommand("command", "Description etc...", command => command
.HandledBy((SomeService service) => service.ExecuteAsync()))
.AddCommand("command2", "Description etc...", command => command
.WithOptions(new
{
option1 = new Option(new[] { "-o", "--option1" }, description: "Some option"),
option2 = new Option(new[] { "-f", "--option2" }, getDefaultValue: () => false, description: "More info")
})
.HandledBy((SomeService2 service, [FromCommand] string option1, [FromCommand] bool option2) => service.Execute(option1, option2)))
.AddCommand("command3", "Description etc... ", command => command
.WithGlobalOptions(new
{
input = new Option(new[] { "-i", "--input" }, () => "BulkOperations\\new-auditors.csv", "The csv file with the required information for the operation"),
output = new Option(new[] { "-o", "--output" }, () => "result", "A drop folder for generated stuff")
})
.AddCommand("subcommand", "Description", subCommand => subCommand
.HandledBy(([FromCommand] string input, [FromCommand] string output) => { throw new NotImplementedException(); }))))
.UseDefaults()
.Build()
.InvokeAsync(args);
```
Contributor guide
Assessment
This issue has not been assessed yet.