Class Horde_Argv_Parser

Description

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)

allow_interspersed_args : 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.)

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

Located in /Argv/lib/Horde/Argv/Parser.php (line 65)

Horde_Argv_OptionContainer
   |
   --Horde_Argv_Parser
Direct descendents
Class Description
 class Horde_Argv_InterceptingParser
 class Horde_Kolab_Filter_Argv_Parser 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).
Variable Summary
Method Summary
 static void matchAbbrev ( $s,  $wordmap)
 Horde_Argv_Parser __construct ([ $args = array()])
 void __destruct ()
 void addOptionGroup ()
 void checkValues ( $values,  $args)
 void expandProgName ( $s)
 void formatEpilog ( $formatter)
 void formatHelp ([ $formatter = null])
 void formatOptionHelp ([ $formatter = null])
 void getDescription ()
 void getOptionGroup ( $opt_str)
 void getProgName ()
 void getUsage ([ $formatter = null])
 void getVersion ()
 void parseArgs ([ $args = null], [ $values = null])
 void parserError (string $msg)
 void parserExit ([ $status = 0], [ $msg = null])
 void printHelp ([ $file = null])
 void printUsage ([ $file = null])
 void printVersion ([ $file = null])
 void setDefault ( $dest,  $value)
 void setDefaults ( $defaults)
 void setUsage ( $usage)
 void _addHelpOption ()
 void _getAllOptions ()
 void _getArgs ([ $args = null])
 void _matchLongOpt ( $opt)
 void _populateOptionList ( $optionList, [ $add_help = true])
 void _processArgs ( &$largs,  &$rargs,  &$values)
 void _processLongOpt ( &$rargs,  &$values)
 void _processShortOpts ( &$rargs,  &$values)
Variables
mixed $optionGroups = array() (line 70)
  • access: public
mixed $standardOptionList = array() (line 67)
  • access: public
mixed $_usage (line 69)
  • access: protected

Inherited Variables

Inherited from Horde_Argv_OptionContainer

Horde_Argv_OptionContainer::$conflictHandler
Horde_Argv_OptionContainer::$defaults
Horde_Argv_OptionContainer::$description
Horde_Argv_OptionContainer::$longOpt
Horde_Argv_OptionContainer::$optionClass
Horde_Argv_OptionContainer::$optionList
Horde_Argv_OptionContainer::$shortOpt
Methods
static matchAbbrev (line 407)

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

  • access: public
static void matchAbbrev ( $s,  $wordmap)
  • $s
  • $wordmap
Constructor __construct (line 72)
  • access: public
Horde_Argv_Parser __construct ([ $args = array()])
  • $args

Redefinition of:
Horde_Argv_OptionContainer::__construct()
Initialize the option list and related data structures.
Destructor __destruct (line 114)

Declare that you are done with this Horde_Argv_Parser. This cleans up reference cycles so the Horde_Argv_Parser (and all objects referenced by it) can be garbage-collected promptly. After calling destroy(), the Horde_Argv_Parser is unusable.

  • access: public
void __destruct ()
addOptionGroup (line 225)
  • access: public
void addOptionGroup ()
checkValues (line 326)

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.

  • access: public
void checkValues ( $values,  $args)
  • $values
  • $args
disableInterspersedArgs (line 184)
  • access: public
void disableInterspersedArgs ()
enableInterspersedArgs (line 179)
  • access: public
void enableInterspersedArgs ()
expandProgName (line 532)
  • access: public
void expandProgName ( $s)
  • $s
formatEpilog (line 641)
  • access: public
void formatEpilog ( $formatter)
  • $formatter
formatHelp (line 646)
  • access: public
void formatHelp ([ $formatter = null])
  • $formatter

Redefinition of:
Horde_Argv_OptionContainer::formatHelp()
formatOptionHelp (line 619)
  • access: public
void formatOptionHelp ([ $formatter = null])
  • $formatter

Redefinition of:
Horde_Argv_OptionContainer::formatOptionHelp()
getDefaultValues (line 208)
  • access: public
void getDefaultValues ()
getDescription (line 537)
  • access: public
void getDescription ()

Redefinition of:
Horde_Argv_OptionContainer::getDescription()
getOptionGroup (line 248)
  • access: public
void getOptionGroup ( $opt_str)
  • $opt_str
getProgName (line 524)
  • access: public
void getProgName ()
getUsage (line 562)
  • access: public
void getUsage ([ $formatter = null])
  • $formatter
getVersion (line 592)
  • access: public
void getVersion ()
parseArgs (line 287)

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.

  • access: public
void parseArgs ([ $args = null], [ $values = null])
  • $args
  • $values
parserError (line 556)

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.

  • access: public
void parserError (string $msg)
  • string $msg

Redefined in descendants as:
parserExit (line 542)
  • access: public
void parserExit ([ $status = 0], [ $msg = null])
  • $status
  • $msg

Redefined in descendants as:
printHelp (line 666)

file : file = stdout

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

  • access: public
void printHelp ([ $file = null])
  • $file
printUsage (line 581)

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

  • access: public
void printUsage ([ $file = null])
  • $file
printVersion (line 608)

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.

  • access: public
void printVersion ([ $file = null])
  • $file
setDefault (line 189)
  • access: public
void setDefault ( $dest,  $value)
  • $dest
  • $value
setDefaults (line 194)
  • access: public
void setDefaults ( $defaults)
  • $defaults
setUsage (line 169)
  • access: public
void setUsage ( $usage)
  • $usage
_addHelpOption (line 135)
  • access: protected
void _addHelpOption ()
_addVersionOption (line 141)
  • access: protected
void _addVersionOption ()
_createOptionList (line 128)
  • access: protected
void _createOptionList ()
_getAllOptions (line 199)
  • access: protected
void _getAllOptions ()
_getArgs (line 267)
  • access: protected
void _getArgs ([ $args = null])
  • $args
_initParsingState (line 159)
  • access: protected
void _initParsingState ()
_matchLongOpt (line 395)

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.

  • access: protected
void _matchLongOpt ( $opt)
  • $opt
_populateOptionList (line 147)
  • access: protected
void _populateOptionList ( $optionList, [ $add_help = true])
  • $optionList
  • $add_help
_processArgs (line 341)

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

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

  • access: protected
void _processArgs ( &$largs,  &$rargs,  &$values)
  • &$largs
  • &$rargs
  • &$values
_processLongOpt (line 434)
  • access: protected
void _processLongOpt ( &$rargs,  &$values)
  • &$rargs
  • &$values
_processShortOpts (line 475)
  • access: protected
void _processShortOpts ( &$rargs,  &$values)
  • &$rargs
  • &$values

Inherited Methods

Inherited From Horde_Argv_OptionContainer

 Horde_Argv_OptionContainer::__construct()
 Horde_Argv_OptionContainer::addOption()
 Horde_Argv_OptionContainer::addOptions()
 Horde_Argv_OptionContainer::formatDescription()
 Horde_Argv_OptionContainer::formatHelp()
 Horde_Argv_OptionContainer::formatOptionHelp()
 Horde_Argv_OptionContainer::getDescription()
 Horde_Argv_OptionContainer::getOption()
 Horde_Argv_OptionContainer::hasOption()
 Horde_Argv_OptionContainer::removeOption()
 Horde_Argv_OptionContainer::setConflictHandler()
 Horde_Argv_OptionContainer::setDescription()
 Horde_Argv_OptionContainer::_checkConflict()
 Horde_Argv_OptionContainer::_createOptionMappings()
 Horde_Argv_OptionContainer::_shareOptionMappings()

Documentation generated on Sun, 30 Jan 2011 05:20:16 +0000 by phpDocumentor 1.4.3