dotnet/command-line-api

Mutually exclusive options

开放

#381 创建于 2019年1月20日

 (16 条评论) (14 个反应) (0 位负责人)C# (421 个派生)auto 404
Area-Parser and Binderenhancementhelp wanted

仓库指标

星标
 (3,665 个星标)
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;
}

贡献者指南