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

Commit

Permalink
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 11 deletions.
6 changes: 2 additions & 4 deletions src/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public function writeLine($text = "", $color = null, $bgColor = null)
} elseif ($width == $consoleWidth) {
$this->write($text, $color, $bgColor);
} else {
$this->write($text . "\n", $color, $bgColor);
$this->write($text, $color, $bgColor);
$this->write("\n");
}
}

Expand Down Expand Up @@ -223,9 +224,6 @@ public function writeBox(
case static::FILL_SHADE_DARK:
$fillChar = $charset::SHADE_DARK;
break;
case static::FILL_SHADE_LIGHT:
$fillChar = $charset::SHADE_LIGHT;
break;
case static::FILL_BLOCK:
default:
$fillChar = $charset::BLOCK;
Expand Down
8 changes: 4 additions & 4 deletions src/Adapter/Posix.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Posix extends AbstractAdapter
*/
protected static $ansiColorMap = array(
'fg' => array(
Color::NORMAL => '22;39m',
Color::RESET => '22;39m',
Color::NORMAL => '22;39',
Color::RESET => '22;39',

Color::BLACK => '0;30',
Color::RED => '0;31',
Expand All @@ -65,8 +65,8 @@ class Posix extends AbstractAdapter
Color::LIGHT_WHITE => '1;37',
),
'bg' => array(
Color::NORMAL => '0;49m',
Color::RESET => '0;49m',
Color::NORMAL => '0;49',
Color::RESET => '0;49',

Color::BLACK => '40',
Color::RED => '41',
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getWidth()
}

if (count($this->probeResult) && (int) $this->probeResult[0]) {
$width = (int)$this->probeResult[0];
$width = (int) $this->probeResult[0];
} else {
$width = parent::getWidth();
}
Expand Down
8 changes: 7 additions & 1 deletion src/Getopt.php
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function sendContent()
public function send()
{
$this->sendContent();
$errorLevel = (int)$this->getMetadata('errorLevel',0);
$errorLevel = (int) $this->getMetadata('errorLevel',0);
exit($errorLevel);
}
}
29 changes: 29 additions & 0 deletions test/GetoptTest.php
Original file line number Diff line number Diff line change
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 f66f985

Please sign in to comment.