Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix Zend\Console\Getopt::getUsageMessage() #3047

Closed
wants to merge 1 commit into from

2 participants

@TimWolla

Getopt::getUsageMessage() no longer throws a warning, when freeform flags
are available and the parameters are already parsed via Getopt::parse().
Freeform flags will not show up in Getopt::getUsageMessage().

Added two tests to ensure this.

@TimWolla TimWolla Fix Zend\Console\Getopt::getUsageMessage()
Getopt::getUsageMessage() no longer throws a warning, when freeform flags
are available and the parameters are already parsed via Getopt::parse().
Freeform flags will not show up in Getopt::getUsageMessage().

Added two tests to ensure this.
11504b3
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3047'
Close #3047
390e0a7
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3047' into develop
Forward port #3047
852b3f5
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-console
@weierophinney weierophinney Merge branch 'hotfix/3047' a811ae5
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-console
@weierophinney weierophinney Merge branch 'hotfix/3047' into develop 80ab2e3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 21, 2012
  1. @TimWolla

    Fix Zend\Console\Getopt::getUsageMessage()

    TimWolla authored
    Getopt::getUsageMessage() no longer throws a warning, when freeform flags
    are available and the parameters are already parsed via Getopt::parse().
    Freeform flags will not show up in Getopt::getUsageMessage().
    
    Added two tests to ensure this.
This page is out of date. Refresh to see the latest.
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(
Something went wrong with that request. Please try again.