commandlineparser / commandlineparser/commandline
Is there a way to implement multiple level verbs?
- 主要語言
- 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