Skip to content
On this page

Help Text

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:

cs
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; }
}

snippet source | anchor

or on the command class itself:

cs
[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;
        }

        AnsiConsole.MarkupLine($"[{input.Color}]{text}[/]");

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

snippet source | anchor

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.