dotnet/command-line-api

Mutually exclusive options

Aberta

#381 aberto em 20 de jan. de 2019

 (16 comentários) (14 reações) (0 responsável)C# (421 forks)auto 404
Area-Parser and Binderenhancementhelp wanted

Métricas do repositório

Stars
 (3.665 estrelas)
Métricas de merge de PR
 (Mesclagem média 38d 3h) (3 fundiu PRs em 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 <tenant-id> option, but never both.

public static Command Rebuild(IContainer container)
{
    var rebuild = new Command("rebuild", "Rebuilds a search index for one (--tenant <tenant-id>) or all (--all) tenants.")
    {
        Handler = CommandHandler.Create<bool, Guid>((all, tenant) =>
            container.Resolve<SearchRebuildTask>().ExecuteAsync(all, tenant))
    };

    rebuild.AddOption(new Option(new[] {"--all", "-a"},
        "Indicates if all tenants should be rebuilt.",
        new Argument<bool>(false) {Arity = ArgumentArity.ZeroOrOne}));

    rebuild.AddOption(new Option(new[] {"--tenant", "-t"},
        "Specifies the specific tenant that should be rebuilt.",
        new Argument<Guid> {Arity = ArgumentArity.ZeroOrOne}));

    return rebuild;
}

Guia do colaborador