Exemple #1
0
 /**
  * Dispatches the given option or store the option to dispatch it later.
  *
  * @param Console_CommandLine_Option $option The option instance
  * @param string                     $token  Command line token to parse
  * @param Console_CommandLine_Result $result The result instance
  *
  * @return void
  */
 private function _dispatchAction($option, $token, $result)
 {
     //var_dump($token);
     $option->dispatchAction($token, $result, $this);
 }
 /**
  * Dispatches the given option or store the option to dispatch it later.
  *
  * @param Console_CommandLine_Option $option The option instance
  * @param string                     $token  Command line token to parse
  * @param Console_CommandLine_Result $result The result instance
  *
  * @return void
  */
 private function _dispatchAction($option, $token, $result)
 {
     if ($option->action == 'Password') {
         $this->_dispatchLater[] = array($option, $token, $result);
     } else {
         $option->dispatchAction($token, $result, $this);
     }
 }
Exemple #3
0
 /**
  * Add an option to the command line parser.
  *
  * Add an option with the name (variable name) $optname and set its 
  * attributes with the array $params, then return the
  * Console_CommandLine_Option instance created.
  * The method accepts another form: you can directly pass a 
  * Console_CommandLine_Option object as the sole argument, this allows to
  * contruct  the option separately, in order to reuse an option in
  * different command line parsers or commands for example.
  *
  * Example:
  * <code>
  * $parser = new Console_CommandLine();
  * $parser->addOption('path', array(
  *     'short_name'  => '-p',  // a short name
  *     'long_name'   => '--path', // a long name
  *     'description' => 'path to the dir', // a description msg
  *     'action'      => 'StoreString',
  *     'default'     => '/tmp' // a default value
  * ));
  * $parser->parse();
  * </code>
  *
  * In a terminal, the help will be displayed like this:
  * <code>
  * $ myscript.php --help
  * Usage: myscript.php [options]
  *
  * Options:
  *   -h, --help  display this help message and exit
  *   -p, --path  path to the dir
  *
  * </code>
  *
  * Various methods to specify an option, these 3 commands are equivalent:
  * <code>
  * $ myscript.php --path=some/path
  * $ myscript.php -p some/path
  * $ myscript.php -psome/path
  * </code>
  *
  * @param mixed $name   a string containing the option name or an
  *                      instance of Console_CommandLine_Option
  * @param array $params an array containing the option attributes
  *
  * @return object Console_CommandLine_Option
  * @access public
  * @see    Console_CommandLine_Option
  */
 public function addOption($name, $params = array())
 {
     include_once 'Console/CommandLine/Option.php';
     if ($name instanceof Console_CommandLine_Option) {
         $opt = $name;
     } else {
         $opt = new Console_CommandLine_Option($name, $params);
     }
     $opt->validate();
     $this->options[$opt->name] = $opt;
     return $opt;
 }