Fixing issue where exceptions for missing required arguments would be raised when trying to get help.

This commit is contained in:
mark_story 2010-10-11 22:53:23 -04:00
parent 43646b9372
commit 2af684cbec
2 changed files with 15 additions and 1 deletions

View file

@ -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())
);

View file

@ -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.
*