Documentation

Parser extends OptionContainer
in package

Horde command-line argument parsing package.

Class attributes: standardOptionList : [Option] list of standard options that will be accepted by all instances of this parser class (intended to be overridden by subclasses).

Instance attributes: usage : string a usage string for your program. Before it is displayed to the user, "%prog" will be expanded to the name of your program ($this->prog or os.path.basename(sys.argv[0])). prog : string the name of the current program (to override os.path.basename(sys.argv[0])). epilog : string paragraph of help text to print after option help

optionGroups : [OptionGroup] list of option groups in this parser (option groups are irrelevant for parsing the command-line, but very useful for generating help)

allowInterspersedArgs : bool = true if true, positional arguments may be interspersed with options. Assuming -a and -b each take a single argument, the command-line -ablah foo bar -bboo baz will be interpreted the same as -ablah -bboo -- foo bar baz If this flag were false, that command line would be interpreted as -ablah -- foo bar -bboo baz -- ie. we stop processing options as soon as we see the first non-option argument. (This is the tradition followed by Python's getopt module, Perl's Getopt::Std, and other argument- parsing libraries, but it is generally annoying to users.)

allowUnknownArgs : bool = false if true, unrecognized arguments will be auto-created, instead of throwing a BadOptionException.

ignoreUnknownArgs : bool = false if true, unrecognized arguments will be silently skipped, instead of throwing a BadOptionException.

rargs : [string] the argument list currently being parsed. Only set when parseArgs() is active, and continually trimmed down as we consume arguments. Mainly there for the benefit of callback options. largs : [string] the list of leftover arguments that we have skipped while parsing options. If allowInterspersedArgs is false, this list is always empty. values : Values the set of option values currently being accumulated. Only set when parseArgs() is active. Also mainly for callbacks.

Tags
category

Horde

author

Chuck Hagenbuch chuck@horde.org

author

Mike Naberezny mike@maintainable.com

copyright

2010-2017 Horde LLC

license

http://www.horde.org/licenses/bsd BSD

Table of Contents

$conflictHandler  : mixed
$defaults  : mixed
$description  : mixed
$longOpt  : mixed
$optionClass  : mixed
$optionGroups  : mixed
$optionList  : mixed
$shortOpt  : mixed
$standardOptionList  : mixed
$_usage  : mixed
__construct()  : mixed
Initialize the option list and related data structures.
addOption()  : mixed
addOptionGroup()  : mixed
addOptions()  : mixed
checkValues()  : mixed
Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.
disableInterspersedArgs()  : mixed
enableInterspersedArgs()  : mixed
expandProgName()  : mixed
formatDescription()  : mixed
formatEpilog()  : mixed
formatHelp()  : mixed
formatOptionHelp()  : mixed
getDefaultValues()  : mixed
getDescription()  : mixed
getOption()  : mixed
getOptionGroup()  : mixed
getProgName()  : mixed
getUsage()  : mixed
getVersion()  : mixed
hasOption()  : mixed
matchAbbrev()  : mixed
(s : string, wordmap : {string : Option}) -> string
parseArgs()  : mixed
Parse the command-line options found in 'args' (default: sys.argv[1:]). Any errors result in a call to 'parserError()', which by default prints the usage message to stderr and calls exit() with an error message. On success returns a pair (values, args) where 'values' is an Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options.
parserError()  : mixed
Print a usage message incorporating $msg to stderr and exit.
parserExit()  : mixed
printHelp()  : mixed
file : file = stdout
printUsage()  : mixed
(file : file = stdout)
printVersion()  : mixed
file : file = stdout
removeOption()  : mixed
setConflictHandler()  : mixed
setDefault()  : mixed
setDefaults()  : mixed
setDescription()  : mixed
setUsage()  : mixed
_addHelpOption()  : mixed
_addVersionOption()  : mixed
_checkConflict()  : mixed
_createOptionList()  : mixed
_createOptionMappings()  : mixed
For use by Horde_Argv_Parser constructor -- create the master option mappings used by this Horde_Argv_Parser and all OptionGroups that it owns.
_getAllOptions()  : mixed
_getArgs()  : mixed
_initParsingState()  : mixed
_matchLongOpt()  : mixed
opt : string) -> string
_populateOptionList()  : mixed
_processArgs()  : mixed
_process_args(largs : [string], rargs : [string], values : Values)
_processLongOpt()  : mixed
_processShortOpts()  : mixed
_shareOptionMappings()  : mixed
For use by OptionGroup constructor -- use shared option mappings from the Horde_Argv_Parser that owns this OptionGroup.

Properties

$optionGroups

public mixed $optionGroups = array()

$standardOptionList

public mixed $standardOptionList = array()

Methods

__construct()

Initialize the option list and related data structures.

public __construct([mixed $args = array() ]) : mixed

This method must be provided by subclasses, and it must initialize at least the following instance attributes: optionList, shortOpt, longOpt, defaults.

Parameters
$args : mixed = array()
Return values
mixed

addOptionGroup()

public addOptionGroup() : mixed
Return values
mixed

addOptions()

public addOptions(mixed $optionList) : mixed
Parameters
$optionList : mixed
Return values
mixed

checkValues()

Check that the supplied option values and leftover arguments are valid. Returns the option values and leftover arguments (possibly adjusted, possibly completely new -- whatever you like). Default implementation just returns the passed-in values; subclasses may override as desired.

public checkValues(mixed $values, mixed $args) : mixed
Parameters
$values : mixed
$args : mixed
Return values
mixed

disableInterspersedArgs()

public disableInterspersedArgs() : mixed
Return values
mixed

enableInterspersedArgs()

public enableInterspersedArgs() : mixed
Return values
mixed

expandProgName()

public expandProgName(mixed $s) : mixed
Parameters
$s : mixed
Return values
mixed

formatDescription()

public formatDescription([mixed $formatter = null ]) : mixed
Parameters
$formatter : mixed = null
Return values
mixed

formatEpilog()

public formatEpilog(mixed $formatter) : mixed
Parameters
$formatter : mixed
Return values
mixed

formatHelp()

public formatHelp([mixed $formatter = null ]) : mixed
Parameters
$formatter : mixed = null
Return values
mixed

formatOptionHelp()

public formatOptionHelp([mixed $formatter = null ]) : mixed
Parameters
$formatter : mixed = null
Return values
mixed

getDefaultValues()

public getDefaultValues() : mixed
Return values
mixed

getDescription()

public getDescription() : mixed
Return values
mixed

getOption()

public getOption(mixed $opt_str) : mixed
Parameters
$opt_str : mixed
Return values
mixed

getOptionGroup()

public getOptionGroup(mixed $opt_str) : mixed
Parameters
$opt_str : mixed
Return values
mixed

getProgName()

public getProgName() : mixed
Return values
mixed

getUsage()

public getUsage([mixed $formatter = null ]) : mixed
Parameters
$formatter : mixed = null
Return values
mixed

getVersion()

public getVersion() : mixed
Return values
mixed

hasOption()

public hasOption(mixed $opt_str) : mixed
Parameters
$opt_str : mixed
Return values
mixed

matchAbbrev()

(s : string, wordmap : {string : Option}) -> string

public static matchAbbrev(mixed $s, mixed $wordmap) : mixed

Return the string key in 'wordmap' for which 's' is an unambiguous abbreviation. If 's' is found to be ambiguous or doesn't match any of 'words', raise BadOptionError.

Parameters
$s : mixed
$wordmap : mixed
Return values
mixed

parseArgs()

Parse the command-line options found in 'args' (default: sys.argv[1:]). Any errors result in a call to 'parserError()', which by default prints the usage message to stderr and calls exit() with an error message. On success returns a pair (values, args) where 'values' is an Values instance (with all your option values) and 'args' is the list of arguments left over after parsing options.

public parseArgs([mixed $args = null ][, mixed $values = null ]) : mixed
Parameters
$args : mixed = null
$values : mixed = null
Return values
mixed

parserError()

Print a usage message incorporating $msg to stderr and exit.

public parserError(string $msg) : mixed

If you override this in a subclass, it should not return -- it should either exit or raise an exception.

Parameters
$msg : string
Return values
mixed

parserExit()

public parserExit(mixed $status[, mixed $msg = null ]) : mixed
Parameters
$status : mixed
$msg : mixed = null
Return values
mixed

printHelp()

file : file = stdout

public printHelp([mixed $file = null ]) : mixed

Print an extended help message, listing all options and any help text provided with them, to 'file' (default stdout).

Parameters
$file : mixed = null
Return values
mixed

printUsage()

(file : file = stdout)

public printUsage([mixed $file = null ]) : mixed

Print the usage message for the current program ($this->_usage) to 'file' (default stdout). Any occurence of the string "%prog" in $this->_usage is replaced with the name of the current program (basename of sys.argv[0]). Does nothing if $this->_usage is empty or not defined.

Parameters
$file : mixed = null
Return values
mixed

printVersion()

file : file = stdout

public printVersion([mixed $file = null ]) : mixed

Print the version message for this program ($this->version) to 'file' (default stdout). As with printUsage(), any occurence of "%prog" in $this->version is replaced by the current program's name. Does nothing if $this->version is empty or undefined.

Parameters
$file : mixed = null
Return values
mixed

removeOption()

public removeOption(mixed $opt_str) : mixed
Parameters
$opt_str : mixed
Return values
mixed

setConflictHandler()

public setConflictHandler(mixed $handler) : mixed
Parameters
$handler : mixed
Return values
mixed

setDefault()

public setDefault(mixed $dest, mixed $value) : mixed
Parameters
$dest : mixed
$value : mixed
Return values
mixed

setDefaults()

public setDefaults(mixed $defaults) : mixed
Parameters
$defaults : mixed
Return values
mixed

setDescription()

public setDescription(mixed $description) : mixed
Parameters
$description : mixed
Return values
mixed

setUsage()

public setUsage(mixed $usage) : mixed
Parameters
$usage : mixed
Return values
mixed

_addHelpOption()

protected _addHelpOption() : mixed
Return values
mixed

_addVersionOption()

protected _addVersionOption() : mixed
Return values
mixed

_checkConflict()

protected _checkConflict(mixed $option) : mixed
Parameters
$option : mixed
Return values
mixed

_createOptionList()

protected _createOptionList() : mixed
Return values
mixed

_createOptionMappings()

For use by Horde_Argv_Parser constructor -- create the master option mappings used by this Horde_Argv_Parser and all OptionGroups that it owns.

protected _createOptionMappings() : mixed
Return values
mixed

_getAllOptions()

protected _getAllOptions() : mixed
Return values
mixed

_getArgs()

protected _getArgs([mixed $args = null ]) : mixed
Parameters
$args : mixed = null
Return values
mixed

_initParsingState()

protected _initParsingState() : mixed
Return values
mixed

_matchLongOpt()

opt : string) -> string

protected _matchLongOpt(mixed $opt) : mixed

Determine which long option string 'opt' matches, ie. which one it is an unambiguous abbrevation for. Raises BadOptionError if 'opt' doesn't unambiguously match any long option string.

Parameters
$opt : mixed
Return values
mixed

_populateOptionList()

protected _populateOptionList(mixed $optionList[, mixed $add_help = true ]) : mixed
Parameters
$optionList : mixed
$add_help : mixed = true
Return values
mixed

_processArgs()

_process_args(largs : [string], rargs : [string], values : Values)

protected _processArgs(mixed &$largs, mixed &$rargs, mixed &$values) : mixed

Process command-line arguments and populate 'values', consuming options and arguments from 'rargs'. If 'allowInterspersedArgs' is false, stop at the first non-option argument. If true, accumulate any interspersed non-option arguments in 'largs'.

Parameters
$largs : mixed
$rargs : mixed
$values : mixed
Return values
mixed

_processLongOpt()

protected _processLongOpt(mixed &$rargs, mixed &$values) : mixed
Parameters
$rargs : mixed
$values : mixed
Return values
mixed

_processShortOpts()

protected _processShortOpts(mixed &$rargs, mixed &$values) : mixed
Parameters
$rargs : mixed
$values : mixed
Return values
mixed

_shareOptionMappings()

For use by OptionGroup constructor -- use shared option mappings from the Horde_Argv_Parser that owns this OptionGroup.

protected _shareOptionMappings(mixed $parser) : mixed
Parameters
$parser : mixed
Return values
mixed

Search results