Documentation

Option
in package

Defines the Option class and some standard value-checking functions.

Instance attributes: shortOpts : [string] longOpts : [string]

action : string type : string dest : string default : any nargs : int const : any choices : [string] callback : function callbackArgs : (any*) help : string metavar : string

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

SUPPRESS_HELP  = 'SUPPRESS HELP'
SUPPRESS_USAGE  = 'SUPPRESS USAGE'
$ACTIONS  : mixed
The set of actions allowed by option parsers. Explicitly listed here so the constructor can validate its arguments.
$ALWAYS_TYPED_ACTIONS  : mixed
The set of actions which *require* a value type, ie. that always consume an argument from the command line.
$ATTRS  : mixed
The list of instance attributes that may be set through keyword args to the constructor.
$CHECK_METHODS  : mixed
A list of unbound method objects.
$CONST_ACTIONS  : mixed
The set of actions which take a 'const' attribute.
$default  : mixed
$dest  : mixed
$longOpts  : mixed
$NO_DEFAULT  : mixed
Not supplying a default is different from a default of None, so we need an explicit 'not supplied' value.
$shortOpts  : mixed
$STORE_ACTIONS  : mixed
The set of actions that involve storing a value somewhere; also listed just for constructor argument validation. (If the action is one of these, there must be a destination.)
$TYPE_CHECKER  : mixed
Dictionary of argument checking functions, which convert and validate option arguments according to the option type.
$TYPED_ACTIONS  : mixed
The set of actions for which it makes sense to supply a value type, ie. which may consume an argument from the command line.
$TYPES  : mixed
The set of known types for option parsers.
__construct()  : mixed
Constructor.
__toString()  : mixed
_checkAction()  : mixed
_checkCallback()  : mixed
_checkChoice()  : mixed
_checkConst()  : mixed
_checkDest()  : mixed
_checkNargs()  : mixed
_checkType()  : mixed
checkBuiltin()  : mixed
checkChoice()  : mixed
checkValue()  : mixed
convertValue()  : mixed
getOptString()  : mixed
hasDefault()  : mixed
parseNumber()  : mixed
process()  : mixed
takeAction()  : mixed
takesValue()  : mixed
_checkOptStrings()  : mixed
_setAttrs()  : mixed
_setOptStrings()  : mixed

Constants

SUPPRESS_HELP

public mixed SUPPRESS_HELP = 'SUPPRESS HELP'

SUPPRESS_USAGE

public mixed SUPPRESS_USAGE = 'SUPPRESS USAGE'

Properties

$ACTIONS

The set of actions allowed by option parsers. Explicitly listed here so the constructor can validate its arguments.

public mixed $ACTIONS = array('store', 'store_const', 'store_true', 'store_false', 'append', 'append_const', 'count', 'callback', 'help', 'version')

$ALWAYS_TYPED_ACTIONS

The set of actions which *require* a value type, ie. that always consume an argument from the command line.

public mixed $ALWAYS_TYPED_ACTIONS = array('store', 'append')

$ATTRS

The list of instance attributes that may be set through keyword args to the constructor.

public mixed $ATTRS = array('action', 'type', 'dest', 'default', 'nargs', 'const', 'choices', 'callback', 'callbackArgs', 'help', 'metavar')

$CHECK_METHODS

A list of unbound method objects.

public mixed $CHECK_METHODS = array('_checkAction', '_checkType', '_checkChoice', '_checkDest', '_checkConst', '_checkNargs', '_checkCallback')

They are called by the constructor, in order, after all attributes are initialized. The list is created and filled in later, after all the methods are actually defined. (I just put it here because I like to define and document all class attributes in the same place.) Subclasses that add another check*() method should define their own CHECK_METHODS list that adds their check method to those from this class.

$CONST_ACTIONS

The set of actions which take a 'const' attribute.

public mixed $CONST_ACTIONS = array('store_const', 'append_const')

$longOpts

public mixed $longOpts = array()

$NO_DEFAULT

Not supplying a default is different from a default of None, so we need an explicit 'not supplied' value.

public static mixed $NO_DEFAULT = array('NO', 'DEFAULT')

$shortOpts

public mixed $shortOpts = array()

$STORE_ACTIONS

The set of actions that involve storing a value somewhere; also listed just for constructor argument validation. (If the action is one of these, there must be a destination.)

public mixed $STORE_ACTIONS = array('store', 'store_const', 'store_true', 'store_false', 'append', 'append_const', 'count')

$TYPE_CHECKER

Dictionary of argument checking functions, which convert and validate option arguments according to the option type.

public mixed $TYPE_CHECKER = array('int' => 'checkBuiltin', 'long' => 'checkBuiltin', 'float' => 'checkBuiltin', 'complex' => 'checkBuiltin', 'choice' => 'checkChoice')

Signature of checking functions is:

mixed function(Horde_Argv_Option $option, string $opt, string $value)

where

  • $option is the Horde_Argv_Option instance calling the checker
  • $opt is the actual option seen on the command-line (eg. '-a', '--file')
  • $value is the option argument seen on the command-line

The return value should be in the appropriate PHP type for $option->type -- eg. an integer if $option->type == 'int'.

If no checker is defined for a type, arguments will be unchecked and remain strings.

$TYPED_ACTIONS

The set of actions for which it makes sense to supply a value type, ie. which may consume an argument from the command line.

public mixed $TYPED_ACTIONS = array('store', 'append', 'callback')

$TYPES

The set of known types for option parsers.

public mixed $TYPES = array('string', 'int', 'long', 'float', 'complex', 'choice')

Again, listed here for constructor argument validation.

Methods

__construct()

Constructor.

public __construct() : mixed
Return values
mixed

__toString()

public __toString() : mixed
Return values
mixed

_checkAction()

public _checkAction() : mixed
Return values
mixed

_checkCallback()

public _checkCallback() : mixed
Return values
mixed

_checkChoice()

public _checkChoice() : mixed
Return values
mixed

_checkConst()

public _checkConst() : mixed
Return values
mixed

_checkDest()

public _checkDest() : mixed
Return values
mixed

_checkNargs()

public _checkNargs() : mixed
Return values
mixed

_checkType()

public _checkType() : mixed
Return values
mixed

checkBuiltin()

public checkBuiltin(mixed $opt, mixed $value) : mixed
Parameters
$opt : mixed
$value : mixed
Return values
mixed

checkChoice()

public checkChoice(mixed $opt, mixed $value) : mixed
Parameters
$opt : mixed
$value : mixed
Return values
mixed

checkValue()

public checkValue(mixed $opt, mixed $value) : mixed
Parameters
$opt : mixed
$value : mixed
Return values
mixed

convertValue()

public convertValue(mixed $opt, mixed $value) : mixed
Parameters
$opt : mixed
$value : mixed
Return values
mixed

getOptString()

public getOptString() : mixed
Return values
mixed

hasDefault()

public hasDefault() : mixed
Return values
mixed

parseNumber()

public static parseNumber(mixed $value) : mixed
Parameters
$value : mixed
Return values
mixed

process()

public process(mixed $opt, mixed $value, mixed $values, mixed $parser) : mixed
Parameters
$opt : mixed
$value : mixed
$values : mixed
$parser : mixed
Return values
mixed

takeAction()

public takeAction(mixed $action, mixed $dest, mixed $opt, mixed $value, mixed $values, mixed $parser) : mixed
Parameters
$action : mixed
$dest : mixed
$opt : mixed
$value : mixed
$values : mixed
$parser : mixed
Return values
mixed

takesValue()

public takesValue() : mixed
Return values
mixed

_checkOptStrings()

protected _checkOptStrings(mixed $opts) : mixed
Parameters
$opts : mixed
Return values
mixed

_setAttrs()

protected _setAttrs(mixed $attrs) : mixed
Parameters
$attrs : mixed
Return values
mixed

_setOptStrings()

protected _setOptStrings(mixed $opts) : mixed
Parameters
$opts : mixed
Return values
mixed

Search results