diff --git a/cake/console/console_option_parser.php b/cake/console/console_option_parser.php index 80685d9f1..5360c8fa2 100644 --- a/cake/console/console_option_parser.php +++ b/cake/console/console_option_parser.php @@ -436,7 +436,7 @@ class ConsoleOptionParser { } } foreach ($this->_args as $i => $arg) { - if ($arg->isRequired() && !isset($args[$i])) { + if ($arg->isRequired() && !isset($args[$i]) && empty($params['help'])) { throw new RuntimeException( sprintf(__('Missing required arguments. %s is required.'), $arg->name()) ); diff --git a/cake/tests/cases/console/console_option_parser.test.php b/cake/tests/cases/console/console_option_parser.test.php index f80092b4e..c98d25d87 100644 --- a/cake/tests/cases/console/console_option_parser.test.php +++ b/cake/tests/cases/console/console_option_parser.test.php @@ -396,6 +396,20 @@ TEXT; $this->assertEquals($expected, $result, 'Help does not match'); } +/** + * test that no exception is triggered when help is being generated + * + * @return void + */ + function testHelpNoExceptionWhenGettingHelp() { + $parser = new ConsoleOptionParser('mycommand', false); + $parser->addOption('test', array('help' => 'A test option.')) + ->addArgument('model', array('help' => 'The model to make.', 'required' => true)); + + $result = $parser->parse(array('--help')); + $this->assertTrue($result[0]['help']); + } + /** * test help() with options and arguments that have choices. *