commandlineparser / commandlineparser/commandline

Proposal for handling multiple mutual exclusive sets

未关闭
#419 3 条评论 10 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
C#
星标
4.8k
派生
478
PR 合并指标
30 天内没有已合并 PR

描述

As probably already discussed in #79 and #93 I would need to specify multiple mutual exclusive sets.

I would suggest to distinguish between multiple sets at an interface level.

For example I have a command that requires either a workspace name or a path to a workspace. The same command expects a connection name or user-host combination:

```csharp
interface IWorkspaceOptions
{
[Option(Required = true, SetName = "fromName")]
string WorkspaceName { get; set; }

[Option(Required = true, SetName = "Path")]
string FromPath { get; set; }
}

interface IConnectionOptions
{
[Option(Required = true, SetName = "fromName")] // not in the same set as IWorkspaceOptions !
string ConnectionName { get; set; }

[Option(Required = true, SetName = "Params")]
string Host { get; set; }

[Option(SetName = "Params")]
string User { get; set; }
}

class Opts : IWorkspaceOptions, IConnectionOptions
{
public string ConnectionName { get; set; }
public string Host { get; set; }
public string User { get; set; }
public string WorkspaceName { get; set; }
public string FromPath { get; set; }
}
```

I would expect the following command lines to be valid:

```
--WorkspaceName MyWorkspace --ConnectionName MyConnection
--WorkspaceName MyWorkspace --Host 1.2.3.4
--WorkspaceName MyWorkspace --Host 1.2.3.4 --User Foo
--FromPath C:\TMP --ConnectionName MyConnection
--FromPath C:\TMP --Host 1.2.3.4
--FromPath C:\TMP --Host 1.2.3.4 --User Foo
```

and the following invalid:
```--WorkspaceName MyWorkspace```
> Missing required connection options

```--ConnectionName MyConnection```
> Missing workspace options

```--WorkspaceName MyWorkspace --ConnectionName MyConnection --User Foo```
> Invalid mixture of mutual exclusive connection options

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。