Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3047' into develop
Browse files Browse the repository at this point in the history
Forward port #3047
  • Loading branch information
weierophinney committed Dec 10, 2012
2 parents c64ace9 + f868665 commit 38e7d8a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
8 changes: 7 additions & 1 deletion library/Zend/Console/Getopt.php
Expand Up @@ -565,6 +565,9 @@ public function getUsageMessage()
$maxLen = 20;
$lines = array();
foreach ($this->rules as $rule) {
if (isset($rule['isFreeformFlag'])) {
continue;
}
$flags = array();
if (is_array($rule['alias'])) {
foreach ($rule['alias'] as $flag) {
Expand Down Expand Up @@ -763,7 +766,10 @@ protected function _parseSingleOption($flag, &$argv)
// Magic methods in future will use this mark as real flag value
$this->ruleMap[$flag] = $flag;
$realFlag = $flag;
$this->rules[$realFlag] = array('param' => 'optional');
$this->rules[$realFlag] = array(
'param' => 'optional',
'isFreeformFlag' => true
);
} else {
$realFlag = $this->ruleMap[$flag];
}
Expand Down
29 changes: 29 additions & 0 deletions tests/ZendTest/Console/GetoptTest.php
Expand Up @@ -589,6 +589,35 @@ public function testGetoptWithFreeformFlagOptionRecognizeFlagsWithValue()
$this->assertEquals('test', $opts->freeform);
}

public function testGetoptWithFreeformFlagOptionShowHelpAfterParseDoesNotThrowNotices()
{
// this formerly failed, because the index 'alias' is not set for freeform flags.
$opts = new Getopt(
array('colors' => 'Colors-option'),
array('color', '--freeform', 'test', 'zend'),
array(Getopt::CONFIG_FREEFORM_FLAGS => true)
);
$opts->parse();

$opts->getUsageMessage();
}

public function testGetoptWithFreeformFlagOptionShowHelpAfterParseDoesNotShowFreeformFlags()
{
$opts = new Getopt(
array('colors' => 'Colors-option'),
array('color', '--freeform', 'test', 'zend'),
array(Getopt::CONFIG_FREEFORM_FLAGS => true)
);
$opts->parse();

$message = preg_replace('/Usage: .* \[ options \]/',
'Usage: <progname> [ options ]',
$opts->getUsageMessage());
$message = preg_replace('/ /', '_', $message);
$this->assertEquals($message, "Usage:_<progname>_[_options_]\n--colors_____________Colors-option\n");
}

public function testGetoptRaiseExceptionForNumericOptionsByDefault()
{
$opts = new Getopt(
Expand Down

0 comments on commit 38e7d8a

Please sign in to comment.