Class TOptionParser

Unit

Declaration

type TOptionParser = class(TObject)

Description

OptionParser — instantiate one of these for commandline parsing

This class is the main parsing class, although a lot of parsing is handled by TOption and its descendants instead.

Hierarchy

  • TObject
  • TOptionParser

Overview

Fields

Protected FParams: TStringList;
Protected FOptions: TList;
Protected FLeftList: TStringList;
Protected FShortOptionChar: Char;
Protected FLongOptionString: string;

Methods

Protected function GetOption(const AIndex: Integer): TOption;
Protected function GetOptionsCount: Integer;
Protected function GetOptionByLongName(const AName: string): TOption;
Protected function GetOptionByShortname(const AName: char): TOption;
Public constructor Create; virtual;
Public constructor CreateParams(const AParams: TStrings); virtual;
Public destructor Destroy; override;
Public function AddOption(const AOption: TOption): TOption;
Public procedure ParseOptions;
Public procedure WriteExplanations;

Properties

Public property LeftList: TStringList read FLeftList;
Public property OptionsCount: Integer read GetOptionsCount;
Public property Options[constAIndex:Integer]: TOption read GetOption;
Public property ByName[constAName:string]: TOption read GetOptionByLongName;
Public property ByShortName[constAName:char]: TOption read GetOptionByShortname;
Public property ShortOptionStart: Char read FShortOptionChar write FShortOptionChar default DefShortOptionChar;
Public property LongOptionStart: String read FLongOptionString write FLongOptionString;

Description

Fields

Protected FParams: TStringList;
 
Protected FOptions: TList;
 
Protected FLeftList: TStringList;
 
Protected FShortOptionChar: Char;
 
Protected FLongOptionString: string;
 

Methods

Protected function GetOption(const AIndex: Integer): TOption;
 
Protected function GetOptionsCount: Integer;
 
Protected function GetOptionByLongName(const AName: string): TOption;
 
Protected function GetOptionByShortname(const AName: char): TOption;
 
Public constructor Create; virtual;

Create without any options — this will parse the current command line

Public constructor CreateParams(const AParams: TStrings); virtual;

Create with parameters to be used instead of command line

Public destructor Destroy; override;

destroy the option parser object and all associated TOption objects

Public function AddOption(const AOption: TOption): TOption;

Add a TOption descendant to be included in parsing the command line

Public procedure ParseOptions;

Parse the specified command line, see also Create

Public procedure WriteExplanations;

output explanations for all options to stdout, will nicely format the output and wrap explanations

Properties

Public property LeftList: TStringList read FLeftList;

This StringList contains all the items from the command line that could not be parsed. Includes options that didn't accept their value and non-options like filenames specified on the command line

Public property OptionsCount: Integer read GetOptionsCount;

The number of option objects that were added to this parser

Public property Options[constAIndex:Integer]: TOption read GetOption;

retrieve an option by index — you can use this and OptionsCount to iterate through the options that this parser owns

Public property ByName[constAName:string]: TOption read GetOptionByLongName;

retrieve an option by its long form. Case sensitivity of the options is taken into account!

Public property ByShortName[constAName:char]: TOption read GetOptionByShortname;

retrieve an option by its short form. Case sensitivity of the options is taken into account!

Public property ShortOptionStart: Char read FShortOptionChar write FShortOptionChar default DefShortOptionChar;

introductory character to be used for short options

Public property LongOptionStart: String read FLongOptionString write FLongOptionString;

introductory string to be used for long options


Generated by PasDoc 0.15.0.