bug #40593 Uses the correct assignment action for console options depending if they are short or long (topikito)
This PR was squashed before being merged into the 4.4 branch.
Discussion
----------
Uses the correct assignment action for console options depending if they are short or long
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #40590
| License | MIT
| Doc PR | -
Checks if the option is short or long, and assigns the corresponding "glue" for the assignment.
Commits
-------
d0a3c538f4
Uses the correct assignment action for console options depending if they are short or long
This commit is contained in:
commit
ffc34fa33c
@ -108,12 +108,13 @@ class ArrayInput extends Input
|
|||||||
$params = [];
|
$params = [];
|
||||||
foreach ($this->parameters as $param => $val) {
|
foreach ($this->parameters as $param => $val) {
|
||||||
if ($param && \is_string($param) && '-' === $param[0]) {
|
if ($param && \is_string($param) && '-' === $param[0]) {
|
||||||
|
$glue = ('-' === $param[1]) ? '=' : ' ';
|
||||||
if (\is_array($val)) {
|
if (\is_array($val)) {
|
||||||
foreach ($val as $v) {
|
foreach ($val as $v) {
|
||||||
$params[] = $param.('' != $v ? '='.$this->escapeToken($v) : '');
|
$params[] = $param.('' != $v ? $glue.$this->escapeToken($v) : '');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
|
$params[] = $param.('' != $val ? $glue.$this->escapeToken($val) : '');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);
|
$params[] = \is_array($val) ? implode(' ', array_map([$this, 'escapeToken'], $val)) : $this->escapeToken($val);
|
||||||
|
@ -162,10 +162,10 @@ class ArrayInputTest extends TestCase
|
|||||||
public function testToString()
|
public function testToString()
|
||||||
{
|
{
|
||||||
$input = new ArrayInput(['-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"]);
|
$input = new ArrayInput(['-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"]);
|
||||||
$this->assertEquals('-f -b=bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
|
$this->assertEquals('-f -b bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
|
||||||
|
|
||||||
$input = new ArrayInput(['-b' => ['bval_1', 'bval_2'], '--f' => ['fval_1', 'fval_2']]);
|
$input = new ArrayInput(['-b' => ['bval_1', 'bval_2'], '--f' => ['fval_1', 'fval_2']]);
|
||||||
$this->assertSame('-b=bval_1 -b=bval_2 --f=fval_1 --f=fval_2', (string) $input);
|
$this->assertSame('-b bval_1 -b bval_2 --f=fval_1 --f=fval_2', (string) $input);
|
||||||
|
|
||||||
$input = new ArrayInput(['array_arg' => ['val_1', 'val_2']]);
|
$input = new ArrayInput(['array_arg' => ['val_1', 'val_2']]);
|
||||||
$this->assertSame('val_1 val_2', (string) $input);
|
$this->assertSame('val_1 val_2', (string) $input);
|
||||||
|
Reference in New Issue
Block a user