/** * 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(); } }
/** * Test that a long set of arguments doesn't make useless output. * * @return void */ public function testHelpWithLotsOfArguments() { $parser = new ConsoleOptionParser('mycommand', false); $parser->addArgument('test', ['help' => 'A test option.'])->addArgument('test2', ['help' => 'A test option.'])->addArgument('test3', ['help' => 'A test option.'])->addArgument('test4', ['help' => 'A test option.'])->addArgument('test5', ['help' => 'A test option.'])->addArgument('test6', ['help' => 'A test option.'])->addArgument('test7', ['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->text(); $expected = 'cake mycommand [-h] [arguments]'; $this->assertContains($expected, $result); }