getValueSuggestions example

$command->complete($completionInput$suggestions);
                }
            }

            /** @var CompletionOutputInterface $completionOutput */
            $completionOutput = new $completionOutput();

            $this->log('<info>Suggestions:</>');
            if ($options = $suggestions->getOptionSuggestions()) {
                $this->log(' --'.implode(' --', array_map(fn ($o) => $o->getName()$options)));
            } elseif ($values = $suggestions->getValueSuggestions()) {
                $this->log(' '.implode(' ', $values));
            } else {
                $this->log(' <comment>No suggestions were provided</>');
            }

            $completionOutput->write($suggestions$output);
        } catch (\Throwable $e) {
            $this->log([
                '<error>Error!</error>',
                (string) $e,
            ]);

            
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Output\OutputInterface;

/** * @author Guillaume Aveline <guillaume.aveline@pm.me> */
class FishCompletionOutput implements CompletionOutputInterface
{
    public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
    {
        $values = $suggestions->getValueSuggestions();
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $values[] = '--'.$option->getName();
            if ($option->isNegatable()) {
                $values[] = '--no-'.$option->getName();
            }
        }
        $output->write(implode("\n", $values));
    }
}
new InputOption('foo', null, InputOption::VALUE_NONE, '', null, ['foo']);
    }

    public function testCompleteArray()
    {
        $values = ['foo', 'bar'];
        $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, $values);
        $this->assertTrue($option->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $option->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }

    public function testCompleteClosure()
    {
        $values = ['foo', 'bar'];
        $option = new InputOption('foo', null, InputOption::VALUE_OPTIONAL, '', null, fn (CompletionInput $input): array => $values);
        $this->assertTrue($option->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $option->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }

    
$argument = new InputArgument('foo', InputArgument::IS_ARRAY);
        $argument->setDefault('default');
    }

    public function testCompleteArray()
    {
        $values = ['foo', 'bar'];
        $argument = new InputArgument('foo', null, '', null, $values);
        $this->assertTrue($argument->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $argument->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }

    public function testCompleteClosure()
    {
        $values = ['foo', 'bar'];
        $argument = new InputArgument('foo', null, '', null, fn (CompletionInput $input): array => $values);
        $this->assertTrue($argument->hasCompletion());
        $suggestions = new CompletionSuggestions();
        $argument->complete(new CompletionInput()$suggestions);
        $this->assertSame($valuesarray_map(fn (Suggestion $suggestion) => $suggestion->getValue()$suggestions->getValueSuggestions()));
    }

    
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Output\OutputInterface;

/** * @author Jitendra A <adhocore@gmail.com> */
class ZshCompletionOutput implements CompletionOutputInterface
{
    public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
    {
        $values = [];
        foreach ($suggestions->getValueSuggestions() as $value) {
            $values[] = $value->getValue().($value->getDescription() ? "\t".$value->getDescription() : '');
        }
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $values[] = '--'.$option->getName().($option->getDescription() ? "\t".$option->getDescription() : '');
            if ($option->isNegatable()) {
                $values[] = '--no-'.$option->getName().($option->getDescription() ? "\t".$option->getDescription() : '');
            }
        }
        $output->write(implode("\n", $values)."\n");
    }
}
$command->complete($completionInput$suggestions);
                }
            }

            /** @var CompletionOutputInterface $completionOutput */
            $completionOutput = new $completionOutput();

            $this->log('<info>Suggestions:</>');
            if ($options = $suggestions->getOptionSuggestions()) {
                $this->log(' --'.implode(' --', array_map(fn ($o) => $o->getName()$options)));
            } elseif ($values = $suggestions->getValueSuggestions()) {
                $this->log(' '.implode(' ', $values));
            } else {
                $this->log(' <comment>No suggestions were provided</>');
            }

            $completionOutput->write($suggestions$output);
        } catch (\Throwable $e) {
            $this->log([
                '<error>Error!</error>',
                (string) $e,
            ]);

            
$completionInput = CompletionInput::fromTokens($input$currentIndex);
        $completionInput->bind($this->command->getDefinition());
        $suggestions = new CompletionSuggestions();

        $this->command->complete($completionInput$suggestions);

        $options = [];
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $options[] = '--'.$option->getName();
        }

        return array_map('strval', array_merge($options$suggestions->getValueSuggestions()));
    }
}
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Output\OutputInterface;

/** * @author Wouter de Jong <wouter@wouterj.nl> */
class BashCompletionOutput implements CompletionOutputInterface
{
    public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
    {
        $values = $suggestions->getValueSuggestions();
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $values[] = '--'.$option->getName();
            if ($option->isNegatable()) {
                $values[] = '--no-'.$option->getName();
            }
        }
        $output->writeln(implode("\n", $values));
    }
}
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Output\OutputInterface;

/** * @author Jitendra A <adhocore@gmail.com> */
class ZshCompletionOutput implements CompletionOutputInterface
{
    public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
    {
        $values = [];
        foreach ($suggestions->getValueSuggestions() as $value) {
            $values[] = $value->getValue().($value->getDescription() ? "\t".$value->getDescription() : '');
        }
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $values[] = '--'.$option->getName().($option->getDescription() ? "\t".$option->getDescription() : '');
            if ($option->isNegatable()) {
                $values[] = '--no-'.$option->getName().($option->getDescription() ? "\t".$option->getDescription() : '');
            }
        }
        $output->write(implode("\n", $values)."\n");
    }
}
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Output\OutputInterface;

/** * @author Wouter de Jong <wouter@wouterj.nl> */
class BashCompletionOutput implements CompletionOutputInterface
{
    public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
    {
        $values = $suggestions->getValueSuggestions();
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $values[] = '--'.$option->getName();
            if ($option->isNegatable()) {
                $values[] = '--no-'.$option->getName();
            }
        }
        $output->writeln(implode("\n", $values));
    }
}
use Symfony\Component\Console\Completion\CompletionSuggestions;
use Symfony\Component\Console\Output\OutputInterface;

/** * @author Guillaume Aveline <guillaume.aveline@pm.me> */
class FishCompletionOutput implements CompletionOutputInterface
{
    public function write(CompletionSuggestions $suggestions, OutputInterface $output): void
    {
        $values = $suggestions->getValueSuggestions();
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $values[] = '--'.$option->getName();
            if ($option->isNegatable()) {
                $values[] = '--no-'.$option->getName();
            }
        }
        $output->write(implode("\n", $values));
    }
}
$completionInput = CompletionInput::fromTokens($input$currentIndex);
        $completionInput->bind($this->command->getDefinition());
        $suggestions = new CompletionSuggestions();

        $this->command->complete($completionInput$suggestions);

        $options = [];
        foreach ($suggestions->getOptionSuggestions() as $option) {
            $options[] = '--'.$option->getName();
        }

        return array_map('strval', array_merge($options$suggestions->getValueSuggestions()));
    }
}
Home | Imprint | This part of the site doesn't use cookies.