示例#1
0
 /**
  * Tests getopt2()
  */
 public function testGetopt2()
 {
     $result = Console_GetoptPlus_Getopt::getopt2();
     $this->assertEquals(array(array(), array()), $result);
 }
 /**
  * Parses the command line
  *
  * See getoptplus() for a complete description.
  *
  * @param  array   $config      the command configuration
  * @param  string  $convertName returns short option names if set to
  *                              "long2short", long ones if set to "short2long",
  *                              as in the command line by default
  * @param  boolean $returnAssoc returns an associative array if true,
  *                              an index array if false
  * @param  string  $ambiguity   directive to handle option names ambiguity:
  *                              "loose", "strict", or "shortcuts"
  * @param  boolean $exitHelp    same as getoptplus()
  * @return array   the parsed options, their arguments and parameters
  * @access public
  */
 public function process($config = array(), $convertName = '', $returnAssoc = false, $ambiguity = '', $exitHelp = true)
 {
     // extracts the command arguments, including the command name
     $args = self::readPHPArgv();
     $command = array_shift($args);
     // checks the options configurations, parses the command
     $config['options'] = $optionsConfig = $this->checkOptionsConfig($config);
     $options = parent::process($args, $optionsConfig, $optionsConfig, $ambiguity);
     // tidies the options
     $options[0] = $this->tidyOptions($options[0], $convertName, $returnAssoc);
     if (is_string($options[0])) {
         // a request for help, builds the command usage,
         $help = Console_GetoptPlus_Help::get($config, $command);
         // exits/displays the command usage or returns it
         $exitHelp and exit($help);
         $name = $options[0];
         $options[0] = $returnAssoc ? array($name => $help) : array(array($name, $help));
     }
     return $options;
 }