commandlineparser / commandlineparser/commandline

Is there a way to implement multiple level verbs?

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

描述

**Issue by [akfish](https://github.com/akfish)**
_Thursday Oct 31, 2013 at 19:48 GMT_
_Originally opened as https://github.com/gsscoder/commandline/issues/107_

----

I am trying to make an app with multiple level of verbs, something like:

```
app repo list
app repo add
app account list
```

What I tried is:

``` cs
class Options
{
#region Global Options
//...
#endregion

#region Help
//..
#endregion

#region Verbs
[VerbOption("account", HelpText = "Manage mail accounts")]
public AccountOptions AccountVerb { get; set; }

[VerbOption("repo", HelpText = "Manage repositories")]
public RepoOptions RepoVerb { get; set; }
#endregion
}
```

In each verb, nested a sub verb:

``` cs
class AccountOptions : IOptions
{
[VerbOption("add", HelpText = "Add an account")]
public AddOption AddVerb { get; set; }

//And so on....

public class AddOption : IOptions
{
}
//And so on....

}
```

main:

``` cs
class Program
{
static void Main(string[] args)
{
string theVerb = null;
IOptions theOptions = null;

var options = new Options();
if (CommandLine.Parser.Default.ParseArguments(args, options, (verb, subOptions) =>
{
theVerb = verb;
if (verb != null)
theOptions = subOptions as IOptions;
}))
{
theOptions.Execute(options);
}
else
{
Console.Error.WriteLine("Command line parsing error.");
}
}
}
```

I was able to get first level of verbs to working (e.g. `app repo`, `app account`, as the documents said. But the second level ones (`app account list`, `app account add`) didn't.

So is there a way to do this? Thanks.

贡献指南

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

调研方向

从 Program.Main 和 ParseArguments 调用开始,然后检查如何发现 Options、AccountOptions 和嵌套的 AddOption。使用所示模型复现 app account list 和 app account add,并确定 parser 是否支持嵌套的 VerbOption 定义。完成的标准是所请求的多级命令能够正确解析和分派,并且测试覆盖这些示例。

由索引模型根据 Issue 内容生成。

评估

技术栈
csharp
领域
cli
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
25/100

把新 issue 发到你的邮箱

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