mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding epilog and description to the generate help.
This commit is contained in:
parent
501e63e45d
commit
d3c95bc2c4
2 changed files with 42 additions and 2 deletions
|
@ -270,6 +270,10 @@ class ConsoleOptionParser {
|
|||
*/
|
||||
public function help() {
|
||||
$out = array();
|
||||
if (!empty($this->_description)) {
|
||||
$out[] = $this->_description;
|
||||
$out[] = '';
|
||||
}
|
||||
$out[] = '<info>Usage:</info>';
|
||||
$out[] = $this->_generateUsage();
|
||||
$out[] = '';
|
||||
|
@ -299,6 +303,9 @@ class ConsoleOptionParser {
|
|||
}
|
||||
$out[] = '';
|
||||
}
|
||||
if (!empty($this->_epilog)) {
|
||||
$out[] = $this->_epilog;
|
||||
}
|
||||
return implode("\n", $out);
|
||||
}
|
||||
|
||||
|
|
|
@ -228,7 +228,7 @@ class ConsoleOptionParserTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
function testGetHelpWithOptions() {
|
||||
function testHelpWithOptions() {
|
||||
$parser = new ConsoleOptionParser('mycommand', false);
|
||||
$parser->addOption('test', array('help' => 'A test option.'))
|
||||
->addOption('connection', array(
|
||||
|
@ -255,7 +255,7 @@ TEXT;
|
|||
*
|
||||
* @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))
|
||||
|
@ -279,4 +279,37 @@ other_longer Another argument. <comment>(optional)</comment>
|
|||
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.');
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue