Пример #1
0
 /**
  * Gets formatted help for this parser object.
  * Generates help text based on the description, options, arguments, subcommands and epilog
  * in the parser.
  *
  * @param string|null $subcommand If present and a valid subcommand that has a linked parser.
  *    That subcommands help will be shown instead.
  * @param string $format Define the output format, can be text or xml
  * @param int $width The width to format user content to. Defaults to 72
  * @return string Generated help.
  */
 public function help($subcommand = null, $format = 'text', $width = 72)
 {
     if (isset($this->_subcommands[$subcommand]) && $this->_subcommands[$subcommand]->parser() instanceof self) {
         $subparser = $this->_subcommands[$subcommand]->parser();
         $subparser->command($this->command() . ' ' . $subparser->command());
         return $subparser->help(null, $format, $width);
     }
     $formatter = new HelpFormatter($this);
     if ($format === 'text') {
         return $formatter->text($width);
     }
     if ($format === 'xml') {
         return $formatter->xml();
     }
 }
Пример #2
0
 /**
  * Test xml help as object
  *
  * @return void
  */
 public function testXmlHelpAsObject()
 {
     $parser = new ConsoleOptionParser('mycommand', false);
     $parser->addOption('test', ['help' => 'A test option.'])->addArgument('model', ['help' => 'The model to make.', 'required' => true])->addArgument('other_longer', ['help' => 'Another argument.']);
     $formatter = new HelpFormatter($parser);
     $result = $formatter->xml(false);
     $this->assertInstanceOf('SimpleXmlElement', $result);
 }