commandlineparser / commandlineparser/commandline

Is there a way to implement multiple level verbs?

Offen
#13 13 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

**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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.