Skip to content

Commit f5746f1

Browse files
committed
[Console] Fix autocompletion of argument with default value
1 parent 70d96aa commit f5746f1

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/Symfony/Component/Console/Completion/CompletionInput.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ public function bind(InputDefinition $definition): void
109109
// complete argument value
110110
$this->completionType = self::TYPE_ARGUMENT_VALUE;
111111

112-
$arguments = $this->getArguments();
113-
foreach ($arguments as $argumentName => $argumentValue) {
114-
if (null === $argumentValue) {
112+
foreach ($this->definition->getArguments() as $argumentName => $argument) {
113+
if (!isset($this->arguments[$argumentName])) {
115114
break;
116115
}
117116

117+
$argumentValue = $this->arguments[$argumentName];
118118
$this->completionName = $argumentName;
119119
if (\is_array($argumentValue)) {
120120
$this->completionValue = $argumentValue ? $argumentValue[array_key_last($argumentValue)] : null;
@@ -124,7 +124,7 @@ public function bind(InputDefinition $definition): void
124124
}
125125

126126
if ($this->currentIndex >= \count($this->tokens)) {
127-
if (null === $arguments[$argumentName] || $this->definition->getArgument($argumentName)->isArray()) {
127+
if (!isset($this->arguments[$argumentName]) || $this->definition->getArgument($argumentName)->isArray()) {
128128
$this->completionName = $argumentName;
129129
$this->completionValue = '';
130130
} else {

src/Symfony/Component/Console/Tests/Command/HelpCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function provideCompletionSuggestions()
9292

9393
yield 'nothing' => [
9494
[''],
95-
[],
95+
['completion', 'help', 'list', 'foo:bar'],
9696
];
9797

9898
yield 'command_name' => [

src/Symfony/Component/Console/Tests/Completion/CompletionInputTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,20 @@ public function provideBindWithLastArrayArgumentData()
9797
yield [CompletionInput::fromTokens(['bin/console', 'symfony', 'sen'], 2), 'sen'];
9898
}
9999

100+
public function testBindArgumentWithDefault()
101+
{
102+
$definition = new InputDefinition([
103+
new InputArgument('arg-with-default', InputArgument::OPTIONAL, '', 'default'),
104+
]);
105+
106+
$input = CompletionInput::fromTokens(['bin/console'], 1);
107+
$input->bind($definition);
108+
109+
$this->assertEquals(CompletionInput::TYPE_ARGUMENT_VALUE, $input->getCompletionType(), 'Unexpected type');
110+
$this->assertEquals('arg-with-default', $input->getCompletionName(), 'Unexpected name');
111+
$this->assertEquals('', $input->getCompletionValue(), 'Unexpected value');
112+
}
113+
100114
/**
101115
* @dataProvider provideFromStringData
102116
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy