@@ -303,6 +303,27 @@ public function run(InputInterface $input, OutputInterface $output): int
303303 */
304304 public function complete (CompletionInput $ input , CompletionSuggestions $ suggestions ): void
305305 {
306+ $ definition = $ this ->getDefinition ();
307+ $ values = null ;
308+ if (CompletionInput::TYPE_OPTION_VALUE === $ input ->getCompletionType () && $ definition ->hasOption ($ input ->getCompletionName ())) {
309+ $ values = $ definition ->getOption ($ input ->getCompletionName ())->getValues ();
310+ } elseif (CompletionInput::TYPE_ARGUMENT_VALUE === $ input ->getCompletionType () && $ definition ->hasArgument ($ input ->getCompletionName ())) {
311+ $ values = $ definition ->getArgument ($ input ->getCompletionName ())->getValues ();
312+ }
313+ if (null === $ values ) {
314+ return ;
315+ }
316+ if ($ values instanceof \Closure) {
317+ $ values = $ values ($ input );
318+ if (null === $ values ) {
319+ return ;
320+ }
321+ if (!is_iterable ($ values )) {
322+ throw new LogicException (sprintf ('Callable for %s %s must return an iterable or null. Got "%s". ' , $ input ->getCompletionType (), $ input ->getCompletionName (), get_debug_type ($ values )));
323+ }
324+ }
325+
326+ $ suggestions ->suggestValues (is_array ($ values ) ? $ values : iterator_to_array ($ values ));
306327 }
307328
308329 /**
@@ -426,6 +447,21 @@ public function addArgument(string $name, int $mode = null, string $description
426447 return $ this ;
427448 }
428449
450+ /**
451+ * Set values for input completion.
452+ *
453+ * @throws InvalidArgumentException If the argument is not defined
454+ *
455+ * @return $this
456+ */
457+ public function setArgumentValues (string $ name , \Closure |iterable |null $ values ): static
458+ {
459+ $ this ->definition ->getArgument ($ name )->setValues ($ values );
460+ $ this ->fullDefinition ?->getArgument($ name )->setValues ($ values );
461+
462+ return $ this ;
463+ }
464+
429465 /**
430466 * Adds an option.
431467 *
@@ -445,6 +481,21 @@ public function addOption(string $name, string|array $shortcut = null, int $mode
445481 return $ this ;
446482 }
447483
484+ /**
485+ * Set values for input completion.
486+ *
487+ * @throws InvalidArgumentException If the option is not defined
488+ *
489+ * @return $this
490+ */
491+ public function setOptionValues (string $ name , \Closure |iterable |null $ values ): static
492+ {
493+ $ this ->definition ->getOption ($ name )->setValues ($ values );
494+ $ this ->fullDefinition ?->getOption($ name )->setValues ($ values );
495+
496+ return $ this ;
497+ }
498+
448499 /**
449500 * Sets the name of the command.
450501 *
0 commit comments