Console_CommandLine
[ class tree: Console_CommandLine ] [ index: Console_CommandLine ] [ all elements ]
Packages:
Console_CommandLine


Classes:
Console_CommandLine
Console_CommandLine_Action
Console_CommandLine_Action_Callback
Console_CommandLine_Action_Counter
Console_CommandLine_Action_Help
Console_CommandLine_Action_List
Console_CommandLine_Action_Password
Console_CommandLine_Action_StoreArray
Console_CommandLine_Action_StoreFalse
Console_CommandLine_Action_StoreFloat
Console_CommandLine_Action_StoreInt
Console_CommandLine_Action_StoreString
Console_CommandLine_Action_StoreTrue
Console_CommandLine_Action_Version
Console_CommandLine_Argument
Console_CommandLine_Command
Console_CommandLine_Element
Console_CommandLine_Exception
Console_CommandLine_MessageProvider_Default
Console_CommandLine_Option
Console_CommandLine_Outputter_Default
Console_CommandLine_Renderer_Default
Console_CommandLine_Result
Console_CommandLine_XmlParser
Files:
Action.php
Argument.php
Callback.php
Command.php
CommandLine.php
Counter.php
CustomMessageProvider.php
Default.php
Default.php
Default.php
Element.php
ex1.php
ex2.php
ex3.php
ex4.php
Exception.php
Help.php
List.php
MessageProvider.php
Option.php
Outputter.php
Password.php
Renderer.php
Result.php
StoreArray.php
StoreFalse.php
StoreFloat.php
StoreInt.php
StoreString.php
StoreTrue.php
Version.php
XmlParser.php

Class: Console_CommandLine_Option

Source Location: /Console_CommandLine-1.1.3/Console/CommandLine/Option.php

Class Overview

Console_CommandLine_Element
 |
 --Console_CommandLine_Option

Class that represent a commandline option.


Author(s):

Version:

  • Release: 1.1.3

Copyright:

  • 2007 David JEAN LOUIS

Variables

Methods



Class Details

[line 43]
Class that represent a commandline option.


[ Top ]


Class Variables

$action = 'StoreString'

[line 66]

The option action, defaults to "StoreString".
  • Var: Option action
  • Access: public

Type: string


[ Top ]

$action_params = array()

[line 127]

An associative array of additional params to pass to the class corresponding to the action, this array will also be passed to the callback defined for an action of type Callback, Example:

  1. // for a custom action
  2. $parser->addOption('myoption', array(
  3. 'short_name' => '-m',
  4. 'long_name' => '--myoption',
  5. 'action' => 'MyCustomAction',
  6. 'action_params' => array('foo'=>true, 'bar'=>false)
  7. ));
  8. // if the user type:
  9. // $ <yourprogram> -m spam
  10. // in your MyCustomAction class the execute() method will be called
  11. // with the value 'spam' as first parameter and
  12. // array('foo'=>true, 'bar'=>false) as second parameter

  • Var: Additional parameters to pass to the action
  • Access: public

Type: array


[ Top ]

$add_list_option = false

[line 144]

For options that uses the "choice" property only.

Adds a --list-<choice> option to the parser that displays the list of choices for the option.

  • Var: Whether to add a list option or not
  • Access: public

Type: bool


[ Top ]

$argument_optional = false

[line 135]

For options that expect an argument, this property tells the parser if the option argument is optional and can be ommited.
  • Var: Whether the option arg is optional or not
  • Access: public

Type: bool


[ Top ]

$callback =

[line 102]

The callback function (or method) to call for an action of type Callback, this can be any callable supported by the php function call_user_func.

Example:

  1. $parser->addOption('myoption', array(
  2. 'short_name' => '-m',
  3. 'long_name' => '--myoption',
  4. 'action' => 'Callback',
  5. 'callback' => 'myCallbackFunction'
  6. ));

  • Var: The option callback
  • Access: public

Type: callable


[ Top ]

$choices = array()

[line 82]

An array of possible values for the option. If this array is not empty and the value passed is not in the array an exception is raised.

This only make sense for actions that accept values of course.

  • Var: Valid choices for the option
  • Access: public

Type: array


[ Top ]

$default =

[line 73]

The default value of the option if not provided on the command line.
  • Var: Default value of the option.
  • Access: public

Type: mixed


[ Top ]

$long_name =

[line 59]

The option long name (ex: --verbose).
  • Var: Long name of the option
  • Access: public

Type: string


[ Top ]

$short_name =

[line 52]

The option short name (ex: -v).
  • Var: Short name of the option
  • Access: public

Type: string


[ Top ]



Method Detail

__construct (Constructor) [line 167]

void __construct( [string $name = null], [array $params = array()])

Constructor.
  • Access: public

Overrides Console_CommandLine_Element::__construct() (Constructor.)

Parameters:

string $name — The name of the option
array $params — An optional array of parameters

[ Top ]

dispatchAction [line 241]

void dispatchAction( mixed $value, Console_CommandLine_Result $result, Console_CommandLine $parser)

Formats the value $value according to the action of the option and updates the passed Console_CommandLine_Result object.
  • Throws: Console_CommandLine_Exception
  • Access: public

Parameters:

mixed $value — The value to format
Console_CommandLine_Result $result — The result instance
Console_CommandLine $parser — The parser instance

[ Top ]

expectsArgument [line 217]

bool expectsArgument( )

Returns true if the option requires one or more argument and false otherwise.
  • Return: Whether the option expects an argument or not
  • Access: public

[ Top ]

setDefaults [line 344]

void setDefaults( )

Set the default value according to the configured action.

Note that for backward compatibility issues this method is only called when the 'force_options_defaults' is set to true, it will become the default behaviour in the next major release of Console_CommandLine.

  • Access: public

[ Top ]

toString [line 188]

string toString( [string $delim = ", "])

Returns the string representation of the option.
  • Return: The string representation of the option
  • Todo: use __toString() instead
  • Access: public

Overrides Console_CommandLine_Element::toString() (Returns the string representation of the element.)

Parameters:

string $delim — Delimiter to use between short and long option

[ Top ]

validate [line 280]

void validate( )

Validates the option instance.
  • Todo: use exceptions instead
  • Throws: Console_CommandLine_Exception
  • Access: public

Overrides Console_CommandLine_Element::validate() (Validates the element instance and set it's default values.)
[ Top ]


Documentation generated on 2019年3月11日 15:37:03 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.

AltStyle によって変換されたページ (->オリジナル) /