feat(console): Add support for suggestedValues

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
pull/63218/head
Carl Schwan 7 days ago
parent b85f3837dc
commit ae5f796d0c
No known key found for this signature in database
GPG Key ID: 02325448204E452A
  1. 6
      lib/private/Console/CommandAdapter.php
  2. 2
      lib/public/Console/Attribute/Argument.php
  3. 2
      lib/public/Console/Attribute/Option.php

@ -139,7 +139,7 @@ class CommandAdapter extends Base {
}
$default = $reflection->hasDefaultValue() ? $reflection->getDefaultValue() : null;
$this->addArgument($arg->name, $mode, $arg->description, $default);
$this->addArgument($arg->name, $mode, $arg->description, $default, $arg->suggestedValues);
}
foreach ($this->options as $option) {
@ -169,7 +169,7 @@ class CommandAdapter extends Base {
throw new \LogicException(\sprintf('The option "$%s" of "%s" must have a default value of false.', $name, $reflection->getSourceName()));
}
$this->addOption($option->name, $option->shortcut, InputOption::VALUE_OPTIONAL, $option->description, $default);
$this->addOption($option->name, $option->shortcut, InputOption::VALUE_OPTIONAL, $option->description, $default, $option->suggestedValues);
continue;
}
@ -201,7 +201,7 @@ class CommandAdapter extends Base {
$mode = InputOption::VALUE_REQUIRED;
}
$this->addOption($option->name, $option->shortcut, $mode, $option->description, $default);
$this->addOption($option->name, $option->shortcut, $mode, $option->description, $default, $option->suggestedValues);
}
}

@ -63,11 +63,13 @@ final class Argument {
*
* @param string $description The description of the argument, displayed with the help page
* @param string $name The name of the argument
* @param array|\Closure $suggestedValues An array or a closure that provides suggested values for the argument.
* @since 35.0.0
*/
public function __construct(
public string $description = '',
public string $name = '',
public array|\Closure $suggestedValues = [],
) {
}
}

@ -69,12 +69,14 @@ final class Option {
* @param string $description The description of the option, displayed with the help page
* @param string $name The name of the option
* @param array|string|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param array|\Closure $suggestedValues An array or a closure that provides suggested values for the option.
* @since 35.0.0
*/
public function __construct(
public string $description = '',
public string $name = '',
public array|string|null $shortcut = null,
public array|\Closure $suggestedValues = [],
) {
}
}

Loading…
Cancel
Save