dotnet / dotnet/command-line-api
Mutually exclusive options
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
It would be great to be able to handle mutually exclusive options.
## Example
For example, if I had a command that either took an `--all` option or a `--tenant ` option, but never both.
```csharp
public static Command Rebuild(IContainer container)
{
var rebuild = new Command("rebuild", "Rebuilds a search index for one (--tenant ) or all (--all) tenants.")
{
Handler = CommandHandler.Create((all, tenant) =>
container.Resolve().ExecuteAsync(all, tenant))
};
rebuild.AddOption(new Option(new[] {"--all", "-a"},
"Indicates if all tenants should be rebuilt.",
new Argument(false) {Arity = ArgumentArity.ZeroOrOne}));
rebuild.AddOption(new Option(new[] {"--tenant", "-t"},
"Specifies the specific tenant that should be rebuilt.",
new Argument {Arity = ArgumentArity.ZeroOrOne}));
return rebuild;
}
```
Contributor guide
Assessment
This issue has not been assessed yet.