Built-in help

Go back


ITGlobal.CLI command line parser contains a built-in support for auto-generated help.

Using an auto-generated help

Parser supports two ways to display auto-generated help:

Programmatic usage access

Parser provides a programmatic access to auto-generated help:

var parser = CliParser.NewTreeParser();

// TODO Configure commands and options...
var command = parser.Command("command");

// Get a root usage from parser
var rootUsage = parser.GetUsage();

// Get a command-specific usage from a command
var commandUsage = command.GetUsage();

You may use this data for various purposes, e.g. auto generating MAN pages or text manuals.

Disabling built-in help

In some cases you might need to opt-out built-in help feature.

Customizing help output

You may override the way help output is rendered to console. For example, you might need to localize it or to change its visual style.

In order to archieve that, you will need to:

  1. Implement a IHelpPrinter interface in a custom class (try using HelpPrinterBase to simplify your code):

    public class MyHelpPrinter : HelpPrinterBase
    {
        // TODO implement required methods
    }
    
  2. Pass an instance of IHelpPrinter to ICliParser.UseHelpPrinter() method:

    var parser = CliParser.NewTreeParser();
    parser.UseHelpPrinter(new MyHelpPrinter());