Skip to content

Commit ae5f796

Browse files
committed
feat(console): Add support for suggestedValues
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent b85f383 commit ae5f796

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/private/Console/CommandAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public function configure(): void {
139139
}
140140
$default = $reflection->hasDefaultValue() ? $reflection->getDefaultValue() : null;
141141

142-
$this->addArgument($arg->name, $mode, $arg->description, $default);
142+
$this->addArgument($arg->name, $mode, $arg->description, $default, $arg->suggestedValues);
143143
}
144144

145145
foreach ($this->options as $option) {
@@ -169,7 +169,7 @@ public function configure(): void {
169169
throw new \LogicException(\sprintf('The option "$%s" of "%s" must have a default value of false.', $name, $reflection->getSourceName()));
170170
}
171171

172-
$this->addOption($option->name, $option->shortcut, InputOption::VALUE_OPTIONAL, $option->description, $default);
172+
$this->addOption($option->name, $option->shortcut, InputOption::VALUE_OPTIONAL, $option->description, $default, $option->suggestedValues);
173173
continue;
174174
}
175175

@@ -201,7 +201,7 @@ public function configure(): void {
201201
$mode = InputOption::VALUE_REQUIRED;
202202
}
203203

204-
$this->addOption($option->name, $option->shortcut, $mode, $option->description, $default);
204+
$this->addOption($option->name, $option->shortcut, $mode, $option->description, $default, $option->suggestedValues);
205205
}
206206
}
207207

lib/public/Console/Attribute/Argument.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ final class Argument {
6363
*
6464
* @param string $description The description of the argument, displayed with the help page
6565
* @param string $name The name of the argument
66+
* @param array|\Closure $suggestedValues An array or a closure that provides suggested values for the argument.
6667
* @since 35.0.0
6768
*/
6869
public function __construct(
6970
public string $description = '',
7071
public string $name = '',
72+
public array|\Closure $suggestedValues = [],
7173
) {
7274
}
7375
}

lib/public/Console/Attribute/Option.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,14 @@ final class Option {
6969
* @param string $description The description of the option, displayed with the help page
7070
* @param string $name The name of the option
7171
* @param array|string|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
72+
* @param array|\Closure $suggestedValues An array or a closure that provides suggested values for the option.
7273
* @since 35.0.0
7374
*/
7475
public function __construct(
7576
public string $description = '',
7677
public string $name = '',
7778
public array|string|null $shortcut = null,
79+
public array|\Closure $suggestedValues = [],
7880
) {
7981
}
8082
}

0 commit comments

Comments
 (0)