Class TCommandLineReaderCGI

Unit

Declaration

type TCommandLineReaderCGI = class(TCommandLineReader)

Description

No description available, ancestor TCommandLineReader description follows

A command line reader class that checks for valid arguments and automatically prints a formatted help.



Usage:

  1. Declare all allowed arguments with the corresponding DeclareXXXX functions

  2. Call parse to explicitely read the actual command line (optionally)

  3. Use readXXX to read a declared argument

On the command line arguments can be given in different ways, e.g.

--name=value
/name=value
--name value
/name value
--name="value"
/name="value"

Declared flags can be changed with –enable-flag or –disable-flag or –flag where latter option negates the default value.
File names are checked for spaces, so it is not always necessary to surround them with quotes.

Internally, the allowed command line arguments are called both "properties" and "options".

Example:

var cmdline: TCommandLineReader;
begin
  cmdline := TCommandLineReader.create;

  //Initial declaration of some command line parameters:
  cmdline.declareString('name', 'An example string property');
  cmdline.declareString('foo', 'Another example string property', 'bar');
  cmdline.declareInt('count', 'An example integer property', 123);
  cmdline.declareFlag('flag', 'An example boolean property');

  //cmdline.parse();



  //1. Parsing some command line options
  cmdline.parse('--name="some name" --count 9');

  cmdline.readString('name'); //some name
  cmdline.readString('foo');  //bar
  cmdline.readInt('count');   //9
  cmdline.readFlag('flag');   //false

  cmdline.existsProperty('name'); //true
  cmdline.existsProperty('foo');  //false




  //2. Parsing some other command line options
  cmdline.parse('--foo barbar --flag');

  cmdline.readString('name'); //
  cmdline.readString('foo');  //barbar
  cmdline.readInt('count');   //123
  cmdline.readFlag('flag');   //true

  cmdline.existsProperty('name'); //false
  cmdline.existsProperty('foo');  //true




  //3. Parsing some other command line options
  cmdline.parse('--help');

  //prints automatically generated help to stdout and halts:
  {
  The following command line options are valid:

  --name=<string> 	An example string property
  --foo=<string>  	Another example string property (default: bar)
  --count=<int>   	An example integer property (default: 123)
  --flag          	An example boolean property
  }




  //4. Some more advanced usage
  cmdline.addAbbreviation('f'); //abbreviation for the last option (--flag)
  cmdline.allowDOSStyle := true; //DOS slash options. Default is only true on Windows

  cmdline.parse('/name "x y z" -f /count=1 /foo="abc"');
  cmdline.readString('name'); //x y z
  cmdline.readString('foo');  //abc
  cmdline.readInt('count');   //1
  cmdline.readFlag('flag');   //true

  cmdline.existsProperty('name'); //true
  cmdline.existsProperty('foo');  //true

Hierarchy

Overview

Fields

Public AllowFiles: boolean;

Methods

Public constructor create(); overload;
Public constructor create(request: TCGIRequest; response: TCGIResponse = nil); overload;
Public destructor destroy; override;
Public procedure parse(autoReset: boolean = true); override;
Public function urlEncodeParams: string;

Description

Fields

Public AllowFiles: boolean;

If this is false (=default), parameters declared with declareFile will be disabled

Methods

Public constructor create(); overload;

Creates a reader using the standard CGI interface

Public constructor create(request: TCGIRequest; response: TCGIResponse = nil); overload;

Creates a reader reading the parameters from the given request, and writing errors to the given response

Public destructor destroy; override;
 
Public procedure parse(autoReset: boolean = true); override;

Actually reads the CGI data (called automatically, when a read.. function is called)

Public function urlEncodeParams: string;

Return


Generated by PasDoc 0.16.0.