dotnet/command-line-api

Mutually exclusive options

Open

#381 建立於 2019年1月20日

在 GitHub 查看
 (16 留言) (14 反應) (0 負責人)C# (421 fork)auto 404
Area-Parser and Binderenhancementhelp wanted

倉庫指標

Star
 (3,665 star)
PR 合併指標
 (平均合併 1小時 58分鐘) (30 天內合併 1 個 PR)

描述

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;
}

貢獻者指南