Help Text Edit on GitHub


Oakton comes with its own [Description] attribute that can be applied to fields or properties on the input class to provide help information on usage like this:


public class NameInput
{
    [Description("The name to be printed to the console output")]
    public string Name { get; set; }

    [Description("The color of the text. Default is black")]
    public ConsoleColor Color { get; set; } = ConsoleColor.Black;

    [Description("Optional title preceeding the name")]
    public string TitleFlag { get; set; }
}

or on the command class itself:


[Description("Print somebody's name")]
public class NameCommand : OaktonCommand<NameInput>
{
    public NameCommand()
    {
        // The usage pattern definition here is completely
        // optional
        Usage("Default Color").Arguments(x => x.Name);
        Usage("Print name with specified color").Arguments(x => x.Name, x => x.Color);
    }

    public override bool Execute(NameInput input)
    {
        var text = input.Name;
        if (!string.IsNullOrEmpty(input.TitleFlag))
        {
            text = input.TitleFlag + " " + text;
        }

        // This is a little helper in Oakton for getting
        // cute with colors in the console output
        ConsoleWriter.Write(input.Color, text);


        // Just telling the OS that the command
        // finished up okay
        return true;
    }
}

Also note the explanatory text in the Usage() method above in the case of a command that has multiple valid argument patterns.

To display a list of all the available commands, you can type either:

executable help

or

executable ?

Likewise, to get the usage help for a single command named "clean", use either executable help clean or executable ? clean.