dotnet/command-line-api

Mutually exclusive options

オープン

#381 opened on 2019/01/20

 (16 件のコメント) (14 件のリアクション) (0 人の担当者)C# (421 件のフォーク)auto 404
Area-Parser and Binderenhancementhelp wanted

Repository metrics

Stars
 (3,665 個のスター)
PR merge metrics
 (平均マージ 1h 58m) (30d で 1 merged 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;
}

コントリビューターガイド