Suggestion example


    private $valueSuggestions = [];
    private $optionSuggestions = [];

    /** * Add a suggested value for an input option or argument. * * @return $this */
    public function suggestValue(string|Suggestion $value)static
    {
        $this->valueSuggestions[] = !$value instanceof Suggestion ? new Suggestion($value) : $value;

        return $this;
    }

    /** * Add multiple suggested values at once for an input option or argument. * * @param list<string|Suggestion> $values * * @return $this */
    
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
    {
        if (
            CompletionInput::TYPE_ARGUMENT_VALUE === $input->getCompletionType()
            && 'command' === $input->getCompletionName()
        ) {
            foreach ($this->all() as $name => $command) {
                // skip hidden commands and aliased commands as they already get added below                 if ($command->isHidden() || $command->getName() !== $name) {
                    continue;
                }
                $suggestions->suggestValue(new Suggestion($command->getName()$command->getDescription()));
                foreach ($command->getAliases() as $name) {
                    $suggestions->suggestValue(new Suggestion($name$command->getDescription()));
                }
            }

            return;
        }

        if (CompletionInput::TYPE_OPTION_NAME === $input->getCompletionType()) {
            $suggestions->suggestOptions($this->getDefinition()->getOptions());

            
$suggestions->suggestOptions($options);
        $stream = fopen('php://memory', 'rw+');
        $this->getCompletionOutput()->write($suggestionsnew StreamOutput($stream));
        fseek($stream, 0);
        $this->assertEquals($this->getExpectedOptionsOutput()stream_get_contents($stream));
    }

    public function testValuesOutput()
    {
        $suggestions = new CompletionSuggestions();
        $suggestions->suggestValues([
            new Suggestion('Green', 'Beans are green'),
            new Suggestion('Red', 'Rose are red'),
            new Suggestion('Yellow', 'Canaries are yellow'),
        ]);
        $stream = fopen('php://memory', 'rw+');
        $this->getCompletionOutput()->write($suggestionsnew StreamOutput($stream));
        fseek($stream, 0);
        $this->assertEquals($this->getExpectedValuesOutput()stream_get_contents($stream));
    }
}
public function complete(CompletionInput $input, CompletionSuggestions $suggestions): void
    {
        if (
            CompletionInput::TYPE_ARGUMENT_VALUE === $input->getCompletionType()
            && 'command' === $input->getCompletionName()
        ) {
            foreach ($this->all() as $name => $command) {
                // skip hidden commands and aliased commands as they already get added below                 if ($command->isHidden() || $command->getName() !== $name) {
                    continue;
                }
                $suggestions->suggestValue(new Suggestion($command->getName()$command->getDescription()));
                foreach ($command->getAliases() as $name) {
                    $suggestions->suggestValue(new Suggestion($name$command->getDescription()));
                }
            }

            return;
        }

        if (CompletionInput::TYPE_OPTION_NAME === $input->getCompletionType()) {
            $suggestions->suggestOptions($this->getDefinition()->getOptions());

            

    private array $valueSuggestions = [];
    private array $optionSuggestions = [];

    /** * Add a suggested value for an input option or argument. * * @return $this */
    public function suggestValue(string|Suggestion $value)static
    {
        $this->valueSuggestions[] = !$value instanceof Suggestion ? new Suggestion($value) : $value;

        return $this;
    }

    /** * Add multiple suggested values at once for an input option or argument. * * @param list<string|Suggestion> $values * * @return $this */
    
Home | Imprint | This part of the site doesn't use cookies.