Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Specification

Patrik edited this page Nov 15, 2017 · 9 revisions

This specification does not describe the current state of the library, but where we want it to go.

  • Example
    • Code
    • Definition
    • Execution
    • Help

Example

Code

public abstract class FooSettings
{
    [CommandOption("-f|--foo [FOO]")]
    [Description("Sets the foo.")]
    public string Foo { get; set; }
}

public abstract class BarSettings : FooSettings
{
    [CommandOption("-b|--bar <BAR>")]
    [Description("Resets the bar.")]
    public string Bar { get; set; }
}

public sealed class QuxSettings : BarSettings
{
    [CommandArgument(0, "<QUX>")]
    [DefaultValue(1)]
    [Description("The flux capacitor threshold.")]
    public int Qux { get; set; }
}

[Description("Quxxes the bar and foo")]
public sealed class QuxCommand : Command<QuxSettings>
{
    public int Execute(QuxSettings settings, ILookup<string, string> remaining)
    {
        return 0;
    }
}

Definition

var app = new CommandApp();
app.AddProxy<FooSettings>("foo", foo => 
{
    foo.SetDescription("Executes the foo.")
    foo.AddProxy<BarSettings>("bar", bar => 
    {
        bar.SetDescription("Performs the bar.")
        bar.AddCommand<QuxCommand>("qux");
    });
});

app.Run();

Execution

> example.exe foo --foo=foo bar --bar "bar" qux 3

Foo=foo
Bar=bar
Qux=3

Help

> example.exe

Usage: example.exe [command]

Commands:
  foo         Executes the foo.
> example.exe foo --help

Usage: example.exe foo [options] [command]

Options:
  -f|--foo [FOO]    Sets the foo.

Commands:
  bar         Performs the bar
> example.exe foo bar --help

Usage: example.exe foo bar [options] [command]

Options:
  -b|--bar <BAR>    Resets the bar (required).

Commands:
  qux         Quxxes the bar and foo
> example.exe foo bar qux --help

Usage: example.exe foo bar qux <QUX>

Arguments:
  <QUX>       The flux capacitor threshold (required).
Clone this wiki locally