Interface ICommandBuilder
Unit
Declaration
type ICommandBuilder = interface(IInterface)
Description
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.
Attributes
- GUID['{5CD580B0-B965-4467-B665-CDFDF61651F1}']
Hierarchy
- IInterface
- ICommandBuilder
Overview
Methods
function AddCommand(const ACommand: string; const ADescription: string = ''; ACallback: TCommandCallback = nil; AConstraints: TCommandConstraints = []): ICommandBuilder; overload; |
|
function AddCommand(const ACommand: TAddCommandCallback): ICommandBuilder; overload; |
|
function GetCommands: TArray<ICommand>; |
|
function GetCommandsFound: Integer; |
|
function GetDefaultCommand: ICommand; |
|
function Description(const ADescription: string): ICommandBuilder; |
|
function CheckConstraints(AConstraints: TCommandConstraints): ICommandBuilder; |
|
function OnExecute(ACallback: TCommandCallback): ICommandBuilder; |
|
function AddArgument(const ADescription: string; AConstraint: TArgumentConstraint): ICommandBuilder; |
|
function GetArguments: TArray<IArgument>; |
|
function AddOption(const AFlag, AName, ADescription: string; ANotAllowedFlags: TArray<string> = nil; AConstraint: TOptionConstraint = ocNoValue): ICommandBuilder; |
|
procedure Parse; |
|
function Validate: TArray<string>; |
|
procedure Execute; |
|
function Run: ICommandBuilder; |
|
function CommandSelected: ICommand; |
|
function SetCommandSelected(ACommand: ICommand): ICommandBuilder; |
|
function CommandAsArgument: ICommand; |
|
function SetCommandAsArgument(ACommand: ICommand): ICommandBuilder; |
|
function GetParsedOptions: TArray<IOption>; |
|
function CheckOption(const AOption: string): Boolean; overload; |
|
function CheckOption(const AOption: string; out AValue: string): Boolean; overload; |
|
function GetParsedArguments: TArray<IArgument>; |
|
function GetRawArguments: TArray<string>; |
|
function GetRawOptions: TArray<string>; |
|
function ExeName: string; |
|
function HasCommands: Boolean; |
|
function HasArguments: Boolean; |
|
function HasOptions: Boolean; |
|
function GetInputLn: TInputLnCallback; |
|
procedure SetInputLn(AValue: TInputLnCallback); |
|
function GetOutput: TOutputCallback; |
|
procedure SetOutput(AValue: TOutputCallback); |
|
function GetOutputColor: TOutputColorCallback; |
|
procedure SetOutputColor(AValue: TOutputColorCallback); |
|
function UseArguments(AArguments: TArray<string>): ICommandBuilder; |
|
function UseColorTheme(ATheme: TColorTheme): ICommandBuilder; |
|
function GetColorTheme: TColorTheme; |
|
procedure SetColorTheme(AValue: TColorTheme); |
|
function GetTitle: string; |
|
procedure SetTitle(AValue: string); |
|
function GetUseShortDescriptions: boolean; |
|
procedure SetUseShortDescriptions(AValue: boolean); |
|
function GetState: string; |
|
procedure SetState(AValue: string); |
Properties
property Commands: TArray<ICommand> read GetCommands; |
|
property Arguments: TArray<IArgument> read GetArguments; |
|
property ParsedOptions: TArray<IOption> read GetParsedOptions; |
|
property ParsedArguments: TArray<IArgument> read GetParsedArguments; |
|
property InputLn: TInputLnCallback read GetInputLn write SetInputLn; |
|
property Output: TOutputCallback read GetOutput write SetOutput; |
|
property OutputColor: TOutputColorCallback read GetOutputColor write SetOutputColor; |
|
property ColorTheme: TColorTheme read GetColorTheme write SetColorTheme; |
|
property Title: string read GetTitle write SetTitle; |
|
property UseShortDescriptions: boolean read GetUseShortDescriptions write SetUseShortDescriptions; |
|
property State: string read GetState write SetState; |
Description
Methods
function AddCommand(const ACommand: string; const ADescription: string = ''; ACallback: TCommandCallback = nil; AConstraints: TCommandConstraints = []): ICommandBuilder; overload; |
|
Adds a command that will be available to the user of the command line application.
Parameters
|
function AddCommand(const ACommand: TAddCommandCallback): ICommandBuilder; overload; |
|
Using a callback to add a command to the CommandBuilder. The main purpose of this method is to allow the use of the fluent interface. Ex: CommandBuilder.AddCommand(@Command.Usage.Registry);
Parameters
|
function GetCommands: TArray<ICommand>; |
|
Returns the list of commands configured in CommandBuilder. |
function GetCommandsFound: Integer; |
|
Returns the number of commands found among the arguments passed as parameters after Parse. |
function GetDefaultCommand: ICommand; |
|
Returns the default command if one has been configured. |
function Description(const ADescription: string): ICommandBuilder; |
|
Set the description for the last command that was added.
Description of the command that best describes its purpose.</summay |
function CheckConstraints(AConstraints: TCommandConstraints): ICommandBuilder; |
|
Set the constraints for the last command that was added.
Parameters
|
function OnExecute(ACallback: TCommandCallback): ICommandBuilder; |
|
Set the callback for the last command that was added.
Parameters
|
function AddArgument(const ADescription: string; AConstraint: TArgumentConstraint): ICommandBuilder; |
|
Adds an argument to allow the user to pass a text argument via the command line.
Parameters
|
function GetArguments: TArray<IArgument>; |
|
Returns the list of arguments configured in CommandBuilder. |
function AddOption(const AFlag, AName, ADescription: string; ANotAllowedFlags: TArray<string> = nil; AConstraint: TOptionConstraint = ocNoValue): ICommandBuilder; |
|
Adds an option to the last added command. For both the short and long options, "-" must not be entered at the beginning of them.
Parameters
|
procedure Parse; |
|
Parses parameters passed via command line, matching command names and arguments for further validation. |
function Run: ICommandBuilder; |
|
Executes the TCommandBuilder.Parse, |
function CommandSelected: ICommand; |
|
Returns the selected command after Parse. |
function SetCommandSelected(ACommand: ICommand): ICommandBuilder; |
|
Manually set the selected command. Mostly used for test purpose. |
function CommandAsArgument: ICommand; |
|
Returns a possible command that was passed as an argument to another command. Value is available after Parse. |
function SetCommandAsArgument(ACommand: ICommand): ICommandBuilder; |
|
Manually set the command as argument. Mostly used for test purpose. |
function GetParsedOptions: TArray<IOption>; |
|
Returns the list of valid options found after parse. |
function GetParsedArguments: TArray<IArgument>; |
|
Build a list of IArguments related to selected command, if there are more than one argument provided the list will match one argument parameter by order of the command builder configuration |
function GetRawArguments: TArray<string>; |
|
Returns a list of raw arguments passed as parameters |
function GetRawOptions: TArray<string>; |
|
Returns a list of raw options passed as parameters |
function ExeName: string; |
|
Returns exe name that will be used as command line shell name to start the application. It´s used to outputs usage info. |
function HasCommands: Boolean; |
|
Returns True if CommandBuilder has at least one command configured. |
function HasArguments: Boolean; |
|
Returns True if CommandBuilder has at least one argument configured. |
function HasOptions: Boolean; |
|
Returns True if CommandBuilder has any option configured in any command. |
function GetInputLn: TInputLnCallback; |
|
procedure SetInputLn(AValue: TInputLnCallback); |
|
function GetOutput: TOutputCallback; |
|
procedure SetOutput(AValue: TOutputCallback); |
|
function GetOutputColor: TOutputColorCallback; |
|
procedure SetOutputColor(AValue: TOutputColorCallback); |
|
function UseArguments(AArguments: TArray<string>): ICommandBuilder; |
|
Allows to inject external arguments instead of reading from ParamStr(). Mainly used for testing purposes.
Parameters
|
function UseColorTheme(ATheme: TColorTheme): ICommandBuilder; |
|
Allows to use a different color theme for the too. Returns the CommandBuilder to allow the use of fluent interface.
Parameters
|
function GetColorTheme: TColorTheme; |
|
procedure SetColorTheme(AValue: TColorTheme); |
|
function GetTitle: string; |
|
procedure SetTitle(AValue: string); |
|
function GetUseShortDescriptions: boolean; |
|
procedure SetUseShortDescriptions(AValue: boolean); |
|
function GetState: string; |
|
procedure SetState(AValue: string); |
|
Properties
property Commands: TArray<ICommand> read GetCommands; |
|
Returns the list of commands configured in CommandBuilder. |
property Arguments: TArray<IArgument> read GetArguments; |
|
Returns the list of arguments configured in CommandBuilder. |
property ParsedOptions: TArray<IOption> read GetParsedOptions; |
|
Returns the list of valid options found after parse. |
property ParsedArguments: TArray<IArgument> read GetParsedArguments; |
|
Build a list of IArguments related to selected command, if there are more than one argument provided the list will match one argument parameter by order of the command builder configuration |
property InputLn: TInputLnCallback read GetInputLn write SetInputLn; |
|
Callback procedure used 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. |
property Output: TOutputCallback read GetOutput write SetOutput; |
|
Callback procedure 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. |
property OutputColor: TOutputColorCallback read GetOutputColor write SetOutputColor; |
|
Callback procedure 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. |
property ColorTheme: TColorTheme read GetColorTheme write SetColorTheme; |
|
Color theme that should be used to output colors of commands, a standard theme is provided by Command.Colors unit. Should be changed prior to application execution |
property Title: string read GetTitle write SetTitle; |
|
Application title, should be customized and is displayer on usage info to the user |
property UseShortDescriptions: boolean read GetUseShortDescriptions write SetUseShortDescriptions; |
|
Display only the first line usage description for command usage, the user needs to use help command to see full command description. Default value is false to preserve original function. |
property State: string read GetState write SetState; |
|
State that can be set by user commands allowing better communication between commands and the application. |
Generated by PasDoc 0.16.0.