Navigation Menu

Skip to content

Commit

Permalink
Adding epilog and description to the generate help.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Oct 14, 2010
1 parent 501e63e commit d3c95bc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cake/console/console_option_parser.php
Expand Up @@ -270,6 +270,10 @@ public function parse($argv) {
*/
public function help() {
$out = array();
if (!empty($this->_description)) {
$out[] = $this->_description;
$out[] = '';
}
$out[] = '<info>Usage:</info>';
$out[] = $this->_generateUsage();
$out[] = '';
Expand Down Expand Up @@ -299,6 +303,9 @@ public function help() {
}
$out[] = '';
}
if (!empty($this->_epilog)) {
$out[] = $this->_epilog;
}
return implode("\n", $out);
}

Expand Down
37 changes: 35 additions & 2 deletions cake/tests/cases/console/console_option_parser.test.php
Expand Up @@ -228,7 +228,7 @@ function testPositionalArgNotEnough() {
*
* @return void
*/
function testGetHelpWithOptions() {
function testHelpWithOptions() {
$parser = new ConsoleOptionParser('mycommand', false);
$parser->addOption('test', array('help' => 'A test option.'))
->addOption('connection', array(
Expand All @@ -255,7 +255,7 @@ function testGetHelpWithOptions() {
*
* @return void
*/
function testGetHelpWithOptionsAndArguments() {
function testHelpWithOptionsAndArguments() {
$parser = new ConsoleOptionParser('mycommand', false);
$parser->addOption('test', array('help' => 'A test option.'))
->addArgument('model', array('help' => 'The model to make.', 'required' => true))
Expand All @@ -279,4 +279,37 @@ function testGetHelpWithOptionsAndArguments() {
TEXT;
$this->assertEquals($expected, $result, 'Help does not match');
}

/**
* test description and epilog in the help
*
* @return void
*/
function testDescriptionAndEpilog() {
$parser = new ConsoleOptionParser('mycommand', false);
$parser->description('Description text')
->epilog('epilog text')
->addOption('test', array('help' => 'A test option.'))
->addArgument('model', array('help' => 'The model to make.', 'required' => true));

$result = $parser->help();
$expected = <<<TEXT
Description text
<info>Usage:</info>
cake mycommand [-h] [--test] model
<info>Options:</info>
--help, -h Display this help.
--test A test option.
<info>Arguments:</info>
model The model to make.
epilog text
TEXT;
$this->assertEquals($expected, $result, 'Help is wrong.');
}
}

0 comments on commit d3c95bc

Please sign in to comment.