Skip to content

Creating custom help output

JF Blouin edited this page Apr 10, 2019 · 7 revisions

Help is automatically generated by the library in certain scenarios. Help is generated using a formatter. Help generated when:

  • No command is found, help will print all available commands.
  • Not all arguments are specified, help will print command information.
  • Requested by the caller, using any of the reserved keywords.
  • When you call CommandParser.PrintHelp()

Included formatters

Included in the library are two formatters. They are both located in the CommandLineEngine.Formatter namespace.

Type Use
Console Outputs help to a console.
Text Outputs help to a StringBuilder (passed in constructor).

By default, the Console formatter is used if none is specified.


Creating your help

The library uses IHelpFormatter, located in the root CommandLineEngine namespace when it needs to display help. You can create a class implementing the interface, and simply supply it to the engine.

The interface has a single method to implement with the following parameters:

Property Use
configuration Configuration returned from parsing all commands and parameters.
command Single command to output. Note that the command can be null, and you are expected to print help for all commands in this case.
operationMessages Operation messages from parsing commands and validation of arguments.

You can use base classes in the CommandLineEngine.Formatters, which include some functionnality for console output, or even derive from the built-in ones.

Clone this wiki locally