Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'hotfix/3047'

Close #3047
  • Loading branch information...
commit 390e0a7cee907a0f800f2b8cd7915fbb3cf8fd2a 2 parents 65cf549 + 411fddf
@weierophinney weierophinney authored
View
8 library/Zend/Console/Getopt.php
@@ -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) {
@@ -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];
}
View
29 tests/ZendTest/Console/GetoptTest.php
@@ -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(
Please sign in to comment.
Something went wrong with that request. Please try again.