\Horde_Argv_Parser

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.

Summary

Methods
Properties
Constants
__construct()
setConflictHandler()
setDescription()
getDescription()
addOption()
addOptions()
getOption()
hasOption()
removeOption()
formatOptionHelp()
formatDescription()
formatHelp()
setUsage()
enableInterspersedArgs()
disableInterspersedArgs()
setDefault()
setDefaults()
getDefaultValues()
addOptionGroup()
getOptionGroup()
parseArgs()
checkValues()
matchAbbrev()
getProgName()
expandProgName()
parserExit()
parserError()
getUsage()
printUsage()
getVersion()
printVersion()
formatEpilog()
printHelp()
$description
$optionList
$optionClass
$defaults
$shortOpt
$longOpt
$conflictHandler
$standardOptionList
$optionGroups
No constants found
_createOptionMappings()
_shareOptionMappings()
_checkConflict()
_createOptionList()
_addHelpOption()
_addVersionOption()
_populateOptionList()
_initParsingState()
_getAllOptions()
_getArgs()
_processArgs()
_matchLongOpt()
_processLongOpt()
_processShortOpts()
$_usage
N/A
No private methods found
No private properties found
N/A

Properties

$description

$description : 

Type

$optionList

$optionList : 

Type

$optionClass

$optionClass : 

Type

$defaults

$defaults : 

Type

$shortOpt

$shortOpt : 

Type

$longOpt

$longOpt : 

Type

$conflictHandler

$conflictHandler : 

Type

$standardOptionList

$standardOptionList : 

Type

$optionGroups

$optionGroups : 

Type

$_usage

$_usage : 

Type

Methods

__construct()

__construct(  $args = array()) 

Initialize the option list and related data structures.

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

Parameters

$args

setConflictHandler()

setConflictHandler(  $handler) 

Parameters

$handler

setDescription()

setDescription(  $description) 

Parameters

$description

getDescription()

getDescription() 

addOption()

addOption() 

addOptions()

addOptions(  $optionList) 

Parameters

$optionList

getOption()

getOption(  $opt_str) 

Parameters

$opt_str

hasOption()

hasOption(  $opt_str) 

Parameters

$opt_str

removeOption()

removeOption(  $opt_str) 

Parameters

$opt_str

formatOptionHelp()

formatOptionHelp(  $formatter = null) 

Parameters

$formatter

formatDescription()

formatDescription(  $formatter = null) 

Parameters

$formatter

formatHelp()

formatHelp(  $formatter = null) 

Parameters

$formatter

setUsage()

setUsage(  $usage) 

Parameters

$usage

enableInterspersedArgs()

enableInterspersedArgs() 

disableInterspersedArgs()

disableInterspersedArgs() 

setDefault()

setDefault(  $dest,   $value) 

Parameters

$dest
$value

setDefaults()

setDefaults(  $defaults) 

Parameters

$defaults

getDefaultValues()

getDefaultValues() 

addOptionGroup()

addOptionGroup() 

getOptionGroup()

getOptionGroup(  $opt_str) 

Parameters

$opt_str

parseArgs()

parseArgs(  $args = null,   $values = null) 

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.

Parameters

$args
$values

checkValues()

checkValues(  $values,   $args) 

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.

Parameters

$values
$args

matchAbbrev()

matchAbbrev(  $s,   $wordmap) 

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

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
$wordmap

getProgName()

getProgName() 

expandProgName()

expandProgName(  $s) 

Parameters

$s

parserExit()

parserExit(  $status,   $msg = null) 

Parameters

$status
$msg

parserError()

parserError(string  $msg) 

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

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

Parameters

string $msg

getUsage()

getUsage(  $formatter = null) 

Parameters

$formatter

printUsage()

printUsage(  $file = null) 

(file : file = stdout)

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

getVersion()

getVersion() 

printVersion()

printVersion(  $file = null) 

file : file = stdout

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

formatEpilog()

formatEpilog(  $formatter) 

Parameters

$formatter

printHelp()

printHelp(  $file = null) 

file : file = stdout

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

Parameters

$file

_createOptionMappings()

_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.

_shareOptionMappings()

_shareOptionMappings(  $parser) 

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

Parameters

$parser

_checkConflict()

_checkConflict(  $option) 

Parameters

$option

_createOptionList()

_createOptionList() 

_addHelpOption()

_addHelpOption() 

_addVersionOption()

_addVersionOption() 

_populateOptionList()

_populateOptionList(  $optionList,   $add_help = true) 

Parameters

$optionList
$add_help

_initParsingState()

_initParsingState() 

_getAllOptions()

_getAllOptions() 

_getArgs()

_getArgs(  $args = null) 

Parameters

$args

_processArgs()

_processArgs(  $largs,   $rargs,   $values) 

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

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
$rargs
$values

_matchLongOpt()

_matchLongOpt(  $opt) 

opt : string) -> string

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

_processLongOpt()

_processLongOpt(  $rargs,   $values) 

Parameters

$rargs
$values

_processShortOpts()

_processShortOpts(  $rargs,   $values) 

Parameters

$rargs
$values