diff --git a/cake/console/console_input_argument.php b/cake/console/console_input_argument.php
index b7bd479fc..65358689e 100644
--- a/cake/console/console_input_argument.php
+++ b/cake/console/console_input_argument.php
@@ -74,6 +74,9 @@ class ConsoleInputArgument {
if (!$this->isRequired()) {
$optional = ' (optional)';
}
+ if (!empty($this->_choices)) {
+ $optional .= sprintf(' (choices: %s)', implode('|', $this->_choices));
+ }
return sprintf('%s%s%s', $name, $this->_help, $optional);
}
@@ -84,6 +87,9 @@ class ConsoleInputArgument {
*/
public function usage() {
$name = $this->_name;
+ if (!empty($this->_choices)) {
+ $name = implode('|', $this->_choices);
+ }
if (!$this->isRequired()) {
$name = '[' . $name . ']';
}
diff --git a/cake/console/console_input_option.php b/cake/console/console_input_option.php
index 466012ae1..852abadd2 100644
--- a/cake/console/console_input_option.php
+++ b/cake/console/console_input_option.php
@@ -75,6 +75,9 @@ class ConsoleInputOption {
if (!empty($this->_default) && $this->_default !== true) {
$default = sprintf(__(' (default: %s)'), $this->_default);
}
+ if (!empty($this->_choices)) {
+ $default .= sprintf(' (choices: %s)', implode('|', $this->_choices));
+ }
if (!empty($this->_short)) {
$short = ', -' . $this->_short;
}
@@ -96,6 +99,9 @@ class ConsoleInputOption {
if (!empty($this->_default) && $this->_default !== true) {
$default = ' ' . $this->_default;
}
+ if (!empty($this->_choices)) {
+ $default = ' ' . implode('|', $this->_choices);
+ }
return sprintf('[%s%s]', $name, $default);
}
diff --git a/cake/tests/cases/console/console_option_parser.test.php b/cake/tests/cases/console/console_option_parser.test.php
index 4e9e45d08..a764d1136 100644
--- a/cake/tests/cases/console/console_option_parser.test.php
+++ b/cake/tests/cases/console/console_option_parser.test.php
@@ -368,6 +368,40 @@ cake mycommand [-h] [--test] model [other_longer]
model The model to make.
other_longer Another argument. (optional)
+TEXT;
+ $this->assertEquals($expected, $result, 'Help does not match');
+ }
+
+/**
+ * test help() with options and arguments that have choices.
+ *
+ * @return void
+ */
+ function testHelpWithChoices() {
+ $parser = new ConsoleOptionParser('mycommand', false);
+ $parser->addOption('test', array('help' => 'A test option.', 'choices' => array('one', 'two')))
+ ->addArgument('type', array(
+ 'help' => 'Resource type.',
+ 'choices' => array('aco', 'aro'),
+ 'required' => true
+ ))
+ ->addArgument('other_longer', array('help' => 'Another argument.'));
+
+ $result = $parser->help();
+ $expected = <<Usage:
+cake mycommand [-h] [--test one|two] aco|aro [other_longer]
+
+Options:
+
+--help, -h Display this help.
+--test A test option. (choices: one|two)
+
+Arguments:
+
+type Resource type. (choices: aco|aro)
+other_longer Another argument. (optional)
+
TEXT;
$this->assertEquals($expected, $result, 'Help does not match');
}