/**
  * Test xml help as object
  *
  * @return void
  */
 public function testXmlHelpAsObject()
 {
     $parser = new ConsoleOptionParser('mycommand', false);
     $parser->addOption('test', array('help' => 'A test option.'))->addArgument('model', array('help' => 'The model to make.', 'required' => true))->addArgument('other_longer', array('help' => 'Another argument.'));
     $formatter = new HelpFormatter($parser);
     $result = $formatter->xml(false);
     $this->assertInstanceOf('SimpleXmlElement', $result);
 }
Exemplo n.º 2
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 $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' || $format === true) {
         return $formatter->text($width);
     } elseif ($format === 'xml') {
         return $formatter->xml();
     }
 }