Class ALinearCConsoleApplication

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type ALinearCConsoleApplication = class(AConsoleApplication)

Description

This class represents a single process running as a console application, which expects to receive arguments on its command line and which can parse those arguments with an instance of ALinearCParser.

This class modifies the behavior of AConsoleApplication somewhat: the run method is overridden to call the ALinearCConsoleApplication.defineOptions before calling ALinearCConsoleApplication.parseCommandLine.

Hierarchy

  • ALinearCConsoleApplication

Overview

Fields

Protected MyOptions: ACommandLineOptionDictionary;
Protected MyLog: ALog;

Methods

Protected procedure defineOptions; virtual;
Protected function printHelp(const ThisOption: ACommandLineOption): boolean; virtual;
Protected function printVersion(const ThisOption: ACommandLineOption): boolean; virtual;
Public function init: boolean; override;
Public destructor destroy; override;
Public function parseCommandLine: int64; virtual;
Public function run: integer; override;
Public procedure printHelpTo(const ThisStream: ATextOutputStream); virtual;
Public procedure printVersionTo(const ThisStream: ATextOutputStream; const additionalItems: array of string); virtual;
Public function usageString: string; virtual;
Public function Options: ACommandLineOptionDictionary; virtual;
Public function Log: ALog; virtual;

Description

Fields

Protected MyOptions: ACommandLineOptionDictionary;

Refers to the command line arguments and options accepted by the program

Protected MyLog: ALog;

Refers to the log used for error and diagnostic output by the program

Methods

Protected procedure defineOptions; virtual;

Define the command line options accepted by the program.

This method may be overridden by descendant classes. In the base implementation of ALinearCConsoleApplication, it defines two flag options: one for "help" and one for "version".

Protected function printHelp(const ThisOption: ACommandLineOption): boolean; virtual;

Print usage information for the program.

This method is called automatically by ACommandLineOptionDictionary.handleDirtiedOptions after all command line options have been parsed, if the –help option was specified by the user. The routine simply calls Self.printHelpTo.

Returns

This method always returns False to indicate that the processing of additional options should halt.

Protected function printVersion(const ThisOption: ACommandLineOption): boolean; virtual;

Print version information for the program.

This method is called automatically by ACommandLineOptionDictionary.handleDirtiedOptions after all command line options have been parsed, if the –version option was specified by the user. The routine simply calls Self.printVersionTo.

Returns

This method always returns False to indicate that the processing of additional options should halt.

Public function init: boolean; override;

Initializer

Public destructor destroy; override;

Destroy the application instance.

This method frees ALinearCConsoleApplication.Options, then calls the inherited routine.

Public function parseCommandLine: int64; virtual;

Parse the command line.

This method constructs an instance of AStringStream to represent the command line arguments passed to the program; it then passes that stream to an instance of ALinearCParser, along with the items in ALinearCConsoleApplication.Options, so that the command line can be parsed.

Returns

The value returned by ALinearCParser.parse, which should indicate the number of errors that occurred while parsing.

Public function run: integer; override;

Execute the application.

This method builds on the behavior inherited from AConsoleApplication.run: after calling the inherited routine, it calls Self.defineOptions, then Self.parseCommandLine.

When the command-line arguments have been parsed, this method calls ACommandLineOptionDictionary.handleDirtiedOptions to handle switches which require additional handling. If that method returns False, then the method exits, returning APP_RUN_INCOMPLETE.

If either ALinearCConsoleApplication.Options or ALinearCConsoleApplication.Log are Nil when this method is entered, meaning that no descendant class has constructed a list of options or a log as part of their initialization, then this method will construct a basic instance of each. The log will output to Self.ErrorOut.

Returns

Zero if execution was successful up to the point defined by this method (descendant classes may perform additional execution afterward), non-zero if an error occurred.

Public procedure printHelpTo(const ThisStream: ATextOutputStream); virtual;

Print usage information for the program to the specified stream.

This method first calls Self.usageString to obtain a usage string for the application, which it prints to ThisStream; it then calls ACommandLineOptionsDictionary.printTo on Self.Options.

Public procedure printVersionTo(const ThisStream: ATextOutputStream; const additionalItems: array of string); virtual;

Print version information for the program to the specified stream.

This method is called automatically by ALinearCConsoleApplication.run, after the command line options have been parsed, if the –version option was specified by the user.

The method uses the key/value pairs specified in Self.VersionInfo to print the name of the program and its version. The format of this output is controlled by lcappVersionStringFormat.

Additional items can be specified in the additionalItems array.

Public function usageString: string; virtual;

Construct a usage string for the application.

The usage string is printed whenever the user enters an option in error, and is also printed when the user requests help from the command-line.

The usage string includes the executable name and the name of all rest arguments accepted by the application. The format of the string is controlled by lcappUsageStringFormat.

Public function Options: ACommandLineOptionDictionary; virtual;

Retrieve a reference to the dictionary of command-line options accepted by the program.

The caller should NOT attempt to free the reference returned by this method; that will be done with the application instance is freed.

Public function Log: ALog; virtual;

Retrieve a reference to the log used for error and diagnostic output by the program.

The caller should NOT attempt to free the reference returned by this method; that will be done when the application instance is freed.


Generated by PasDoc 0.13.0 on 2015-06-25 11:07:51