Unit Command.Interfaces

Uses
Functions and Procedures
Constants
Variables

Description

This unit contains interfaces and types used by the library to build and process commands, arguments, options, validations, themes and callback functions that leverage library customization as well as make testing it easier.

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TColorTheme Color theme structure used across the library. All fields in this record represent colors that can be defined from the color constants found in the Command.Colors unit.
Interface IOption Interface representing an option that can be set as expected for a command.
Interface ICommand Interface representing a command that can be registered in CommandBuilder for later use by the user.
Interface IArgument Interface representing an argument that can be registered in CommandBuilder for later use by the user.
Interface ICommandBuilder Interface that represents the CommandBuilder, its main purpose is to configure the arguments, commands and options accepted by the tool. Central point of the library, responsible for comparing and validating the parameters passed via the command line against the configured parameters, later executing the callback linked to the localized command.
Interface IValidatorContext Interface that groups all validators, as well as establishes the validation order.
Interface IValidatorBase Base interface for any validation that needs to be implemented. Specification validations need to inherit from this interface by convention from this library. It already has control for the successor validator as well as its automatic call at the appropriate time.

Types

TCommandConstraint = (...);
TCommandConstraints = set of TCommandConstraint;
TOptionConstraint = (...);
TArgumentConstraint = (...);
TCommandCallback = procedure (ABuilder: ICommandBuilder);
TAddCommandCallback = function (ABuilder: ICommandBuilder): Boolean;
TOutputCallback = procedure (const AMessage: string);
TOutputColorCallback = procedure (const AMessage: string; const AColor: byte);
TInputLnCallback = function: string;

Description

Types

TCommandConstraint = (...);

Enumerated type that defines constraints that apply on commands. It is used to indicate to the CommandBuilder the rules for using the command, allowing its validation to be done automatically.

Values
  • ccDefault: Indicates the default command that will be invoked by the CommandBuilder when a command is not informed through the command line by the user.
  • ccRequiresOneArgument: Indicates that the command requires at least one given argument to be used.
  • ccRequiresOneOption: Indicates that the command requires at least one option entered to be used.
  • ccNoArgumentsButCommands: Indicates that the command requires another command to function and does not accept arguments. A clear example of usage is the help command itself, which can provide instructions for using other commands.
  • ccNoParameters: Indicates that the command should be used without any parameters.
TCommandConstraints = set of TCommandConstraint;

Set type of constraints, as they can have their combined use when configuring a command.

TOptionConstraint = (...);

Enumerated type that defines constraints that apply on options. It is used to indicate to the CommandBuilder the rules for using options, allowing its validation to be done automatically.

Values
  • ocNoValue: Indicates that a value is not accepted for the option.
  • ocRequiresValue: Indicates that a value is required for the option.
  • ocOptionalValue: Indicates that a value is optional for the option.
TArgumentConstraint = (...);

Enumerated type that defines constraints that apply on arguments. It is used to indicate to the CommandBuilder the rules for using arguments, allowing its validation to be done automatically.

Values
  • acRequired: Indicates that the argument is required. Do not use it if one command doest not require any parameters.
  • acOptional: Indicates that the argument is optional.
TCommandCallback = procedure (ABuilder: ICommandBuilder);

Callback procedure signature that represents a command defined in the program.

Parameters
ABuilder
Instance of CommandBuilder that processed, validated, and identified the callback command being called.
TAddCommandCallback = function (ABuilder: ICommandBuilder): Boolean;

Callback function signature need to add a command using the overloaded version of CommandBuilder.AddCommand. This signature is different to avoid collision with the TCommandCallback signature. The return result is not required.

Parameters
ABuilder
Instance of CommandBuilder used to add the command.
TOutputCallback = procedure (const AMessage: string);

Callback procedure signature that is intended to output text to the console, or other desired output. The library provides a standard callback that simply calls WriteLn, but it can be overridden so that the output is redirected to a file, a test function, etc.

Parameters
AMessage
Text that will be printed on output.
TOutputColorCallback = procedure (const AMessage: string; const AColor: byte);

Callback procedure signature that is intended to output text to the console usings colors. The library provides a standard callback that simply calls Write before change console color, but it can be overridden so that the output is redirected to a file, a test function, etc.

Parameters
AMessage
Text that will be printed on output.
AColor
Color that should be used to print the text.
TInputLnCallback = function: string;

Callback procedure signature used by the library to capture user input. A default callback is provided by the library, but it can be overridden for testing purposes primarily. Should return user input.


Generated by PasDoc 0.16.0.