Unit Command.Usage

Uses
Classes, Interfaces, Objects and Records
Types
Constants
Variables

Description

This unit contains functions to display information on how to use the arguments, commands and options configured in TCommandBuilder. Its main command is the UsageCommand which is prepared to provide usage information to the user. To use this procedure, just configure it using TCommandBuilder.AddCommand method or simply call the Registry function of this unit to do that.

Overview

Functions and Procedures

procedure UsageCommand(ABuilder: ICommandBuilder);
function GetArgumentList(ABuilder: ICommandBuilder): string;
procedure WriteUsage(ABuilder: ICommandBuilder; const ATitle, ACommand, AOptions, AArgument: string);
procedure WriteCommandUsage(ABuilder: ICommandBuilder);
procedure WriteGeneralUsage(ABuilder: ICommandBuilder);
function Registry(ABuilder: ICommandBuilder): Boolean;

Description

Functions and Procedures

procedure UsageCommand(ABuilder: ICommandBuilder);

Outputs text describing command usage according to commands, options and arguments configured using application command builder. If a different color theme is specified to the TCommandBuilder.ColorTheme, this command displays the usage info in different colors.

If a given command needs another command as a parameter (for example help command).This command should be configured using ccNoArgumentsButCommands constraint allowing another command to be passed as parameter to UsageCommand.

To use this command, just add the Command.Usage to the uses clause:

uses Command.Usage;

And call Registry procedure to add this command to the builder: Ex:

Command.Usage.Registry(MyApp.CommandBuilder);

or you can use the overloaded version of AddCommand to add the command to the builder using fluent interface:

MyBuilder
  .AddCommand(Command.Usage.Registry);

or customize your own configuration:

MyApp.CommandBuilder
  .AddCommand(
    'help', 
    'Shows information about how to use this tool or about a specific command.' + #13#10 +
    'Ex: ' + ABuilder.ExeName + ' help', 
    @UsageCommand,
    [ccDefault, ccNoArgumentsButCommands]);

Parameters
ABuilder
Instance of CommandBuilder from which the settings will be read to show usage information via the command line.
function GetArgumentList(ABuilder: ICommandBuilder): string;

Returns an argument list configured for CommandBuilder as a simple string. It will be used to display argument usage info to the user.

Parameters
ABuilder
Instance of CommandBuilder from which data will be read.
procedure WriteUsage(ABuilder: ICommandBuilder; const ATitle, ACommand, AOptions, AArgument: string);

Outputs simple usage command using provided parameters for the command provided. Display the usage in the following format 'EXECUTABLE [command] [options]'.

Parameters
ABuilder
Instance of CommandBuilder that will be used to output info through its configured callback procedure.
ATitle
Application title
ACommand
Command name
AOptions
Options list
AArgument
Argument description
procedure WriteCommandUsage(ABuilder: ICommandBuilder);

Outputs full usage information for a specific command. It´s used when the user requests help for a specific command.

Parameters
ABuilder
Instance of CommandBuilder that will be used to output info through its configured callback procedure.
procedure WriteGeneralUsage(ABuilder: ICommandBuilder);

Outputs general help information for the application, including command usage syntax, command list, command description, arguments that are acceptable. Also displays application title and version information.

Parameters
ABuilder
Instance of CommandBuilder that will be used to output info through its configured callback procedure.
function Registry(ABuilder: ICommandBuilder): Boolean;

Configure UsageCommand with standard parameters.

Ex:

Command.Usage.Registry(MyApp.CommandBuilder);

Ex with fluent interface:

Builder.AddCommand(Command.Usage.Registry);

Parameters
ABuilder
CommandBuilder instance that will be used to register the UsageCommand.

Generated by PasDoc 0.16.0.