Skip to content

Commit

Permalink
Fixing formatting on generated help in ConsoleOptionParser.
Browse files Browse the repository at this point in the history
Updating tests.
Making Shell::wrapText a simple wrapper for String::wrap()
  • Loading branch information
markstory committed Oct 16, 2010
1 parent 98a654c commit 46dcf8b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
18 changes: 15 additions & 3 deletions cake/console/console_option_parser.php
Expand Up @@ -491,7 +491,11 @@ public function help($subcommand = null, $width = 72) {
$out[] = '';
$max = $this->_getMaxLength($this->_subcommands) + 2;
foreach ($this->_subcommands as $command) {
$out[] = String::wrap($command->help($max), $width);
$out[] = String::wrap($command->help($max), array(
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
));
}
$out[] = '';
$out[] = sprintf(
Expand All @@ -506,7 +510,11 @@ public function help($subcommand = null, $width = 72) {
$out[] = '<info>Options:</info>';
$out[] = '';
foreach ($this->_options as $option) {
$out[] = String::wrap($option->help($max), $width);
$out[] = String::wrap($option->help($max), array(
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
));
}
$out[] = '';
}
Expand All @@ -515,7 +523,11 @@ public function help($subcommand = null, $width = 72) {
$out[] = '<info>Arguments:</info>';
$out[] = '';
foreach ($this->_args as $argument) {
$out[] = String::wrap($argument->help($max), $width);
$out[] = String::wrap($argument->help($max), array(
'width' => $width,
'indent' => str_repeat(' ', $max),
'indentAt' => 1
));
}
$out[] = '';
}
Expand Down
10 changes: 5 additions & 5 deletions cake/console/libs/bake.php
Expand Up @@ -200,12 +200,12 @@ public function all() {
*/
public function getOptionParser() {
$parser = parent::getOptionParser();
return $parser->description(array(
'The Bake script generates controllers, views and models for your application.',
'If run with no command line arguments, Bake guides the user through the class',
'creation process. You can customize the generation process by telling Bake',
return $parser->description(
'The Bake script generates controllers, views and models for your application.' .
'If run with no command line arguments, Bake guides the user through the class' .
'creation process. You can customize the generation process by telling Bake' .
'where different parts of your application are using command line arguments.'
))->addSubcommand('all', array(
)->addSubcommand('all', array(
'help' => __('Bake a complete MVC. optional <name> of a Model'),
))->addSubcommand('project', array(
'help' => __('Bake a new app folder in the path supplied or in current directory if no path is specified'),
Expand Down
11 changes: 2 additions & 9 deletions cake/console/libs/shell.php
Expand Up @@ -460,17 +460,10 @@ protected function _getInput($prompt, $options, $default) {
* @param string $text Text the text to format.
* @param mixed $options Array of options to use, or an integer to wrap the text to.
* @return string Wrapped / indented text
* @see String::wrap()
*/
public function wrapText($text, $options = array()) {
$wrapped = String::wrap($text, $options);
if (is_array($options) && !empty($options['indent'])) {
$chunks = explode("\n", $wrapped);
foreach ($chunks as &$chunk) {
$chunk = $options['indent'] . $chunk;
}
return implode("\n", $chunks);
}
return $wrapped;
return String::wrap($text, $options);
}

/**
Expand Down
34 changes: 16 additions & 18 deletions cake/tests/cases/console/console_option_parser.test.php
Expand Up @@ -388,7 +388,7 @@ function testHelpWithOptions() {
--help, -h Display this help.
--test A test option.
--connection, -c The connection to use. <comment>(default:
default)</comment>
default)</comment>
TEXT;
$this->assertEquals($expected, $result, 'Help does not match');
Expand Down Expand Up @@ -643,38 +643,36 @@ function testParsingWithSubParser() {
*/
function testWidthFormatting() {
$parser = new ConsoleOptionParser('test', false);
$parser->description(__('This is 10 This is 10'))
->addOption('four', array('help' => 'more text'))
->addArgument('four', array('help' => 'more text'))
->addSubcommand('four', array('help' => 'more text'));
$result = $parser->help(null, 10);
$parser->description(__('This is fifteen This is fifteen This is fifteen'))
->addOption('four', array('help' => 'this is help text this is help text'))
->addArgument('four', array('help' => 'this is help text this is help text'))
->addSubcommand('four', array('help' => 'this is help text this is help text'));
$result = $parser->help(null, 30);
$expected = <<<TEXT
This is 10
This is 10
This is fifteen This is
fifteen This is fifteen
<info>Usage:</info>
cake test [subcommand] [-h] [--four] [<four>]
<info>Subcommands:</info>
four more
text
four this is help text this
is help text
To see help on a subcommand use <info>`cake test [subcommand] --help`</info>
<info>Options:</info>
--help, -h
Display
this help.
--four
more text
--help, -h Display this help.
--four this is help text
this is help text
<info>Arguments:</info>
four more
text
<comment>(optional)</comment>
four this is help text this
is help text
<comment>(optional)</comment>
TEXT;
$this->assertEquals($expected, $result, 'Generated help is too wide');
Expand Down

0 comments on commit 46dcf8b

Please sign in to comment.