ask example

protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);

        if ($this->adminEsHelper->getEnabled() !== true) {
            $io->error('Admin elasticsearch is not enabled');

            return self::FAILURE;
        }

        $answer = $io->ask('Are you sure you want to reset the Admin Elasticsearch indexing?', 'yes');

        if ($answer !== 'yes') {
            $io->error('Canceled clearing indexing process');

            return self::SUCCESS;
        }

        $allIndices = $this->client->indices()->get(['index' => $this->adminEsHelper->getPrefix() . '*']);

        foreach ($allIndices as $index) {
            $this->client->indices()->delete(['index' => $index['settings']['index']['provided_name']]);
        }

    protected function askForAdminLocale($locales)
    {
        $question = new ChoiceQuestion('Please select your admin locale', $locales);
        $question->setErrorMessage('Locale %s is invalid.');

        $shopLocale = $this->IOHelper->ask($question);

        return $shopLocale;
    }

    /** * @param string[] $locales * * @return string */
    protected function askForShopShopLocale($locales$default = null)
    {
        
->addArgument('version', InputArgument::OPTIONAL, 'A version of release. It should be 4-digits type')
            ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Use the --dry-run argument to preview the changelog content and prevent actually writing to file.')
            ->addOption('force', 'f', InputOption::VALUE_NONE, 'Use the --force argument to override an existing release.');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $IOHelper = new SymfonyStyle($input$output);
        $IOHelper->title('Creating or updating the final changelog for a new release');

        $version = $input->getArgument('version')
            ?? $IOHelper->ask('A version of release', null, function D$version) {
                if (!$version) {
                    throw new \RuntimeException('Version of release is required.');
                }

                return $version;
            });
        if (!preg_match("/^\d+(\.\d+){3}$/", (string) $version)) {
            throw new \RuntimeException('Invalid version of release ("' . $version . '"). It should be 4-digits type');
        }

        $force = $input->getOption('force');
        

        return [SIGINT];
    }

    public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false
    {
        exit(0);
    }
})
    ->setCode(function(InputInterface $input, OutputInterface $output) {
        $this->getHelper('question')
             ->ask($input$outputnew ChoiceQuestion('😊', ['y']));

        return 0;
    })
    ->run()

;
public function testGetDisplay()
    {
        $this->assertEquals('foo'.\PHP_EOL, $this->tester->getDisplay(), '->getDisplay() returns the display of the last execution');
    }

    public function testSetInputs()
    {
        $application = new Application();
        $application->setAutoExit(false);
        $application->register('foo')->setCode(function D$input$output) {
            $helper = new QuestionHelper();
            $helper->ask($input$outputnew Question('Q1'));
            $helper->ask($input$outputnew Question('Q2'));
            $helper->ask($input$outputnew Question('Q3'));
        });
        $tester = new ApplicationTester($application);

        $tester->setInputs(['I1', 'I2', 'I3']);
        $tester->run(['command' => 'foo']);

        $tester->assertCommandIsSuccessful();
        $this->assertEquals('Q1Q2Q3', $tester->getDisplay(true));
    }

    
$helperSet = new HelperSet([new FormatterHelper()]);
        $questionHelper->setHelperSet($helperSet);

        $heroes = ['Superman', 'Batman', 'Spiderman'];

        $inputStream = $this->getInputStream("\n1\n 1 \nFabien\n1\nFabien\n1\n0,2\n 0 , 2 \n\n\n");

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '2');
        $question->setMaxAttempts(1);
        // first answer is an empty answer, we're supposed to receive the default value         $this->assertEquals('Spiderman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream)$output = $this->createOutputInterface()$question));
        $this->assertOutputContains('What is your favorite superhero? [Spiderman]', $output);

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
        $question->setMaxAttempts(1);
        $this->assertEquals('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));
        $this->assertEquals('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream)$this->createOutputInterface()$question));

        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes);
        $question->setErrorMessage('Input "%s" is not a superhero!');
        $question->setMaxAttempts(2);
        $this->assertEquals('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream)$output = $this->createOutputInterface()$question));
        
->addOption('author-github', null, InputOption::VALUE_OPTIONAL, 'The author email of code changes')
            ->addOption('dry-run', null, InputOption::VALUE_NONE, 'Use the --dry-run argument to preview the changelog content and prevent actually writing to file.');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $IOHelper = new SymfonyStyle($input$output);
        $IOHelper->title('Create a changelog markdown file');

        $default = $this->getDefaultData();
        $title = $input->getArgument('title')
            ?? $IOHelper->ask('A short meaningful title of your change', null, function D$title) {
                if (!$title) {
                    throw new \RuntimeException('Title is required in changelog file');
                }

                return $title;
            });
        $issue = $input->getArgument('issue')
            ?? $IOHelper->ask('The corresponding Jira ticket ID', null, function D$issue) {
                if (!$issue) {
                    throw new \RuntimeException('Jira ticket ID is required in changelog file');
                }

                
$questionHelper = $this->getHelper('question');

        foreach ($missingSnippetsCollection->getIterator() as $missingSnippetStruct) {
            $question = sprintf(
                "<info>Available translation: '%s' in locale '%s'.</info>\n<question>Please enter translation for locale '%s':</question>",
                $missingSnippetStruct->getAvailableTranslation(),
                $missingSnippetStruct->getAvailableISO(),
                $missingSnippetStruct->getMissingForISO()
            );

            $missingSnippetStruct->setTranslation($questionHelper->ask($input$outputnew Question($question)) ?? '');
        }

        $this->snippetFixer->fix($missingSnippetsCollection);

        return self::SUCCESS;
    }

    private function hydrateMissingSnippets(array $missingSnippetsArray): MissingSnippetCollection
    {
        $missingSnippetsCollection = new MissingSnippetCollection();
        foreach ($missingSnippetsArray as $locale => $missingSnippets) {
            
/** * Helper function to ask the user a question */
    private function askForOptionalData(InputInterface $input, OutputInterface $output, string $optionKey)
    {
        $optionValue = $input->getOption($optionKey);

        if (empty($optionValue)) {
            $questionHelper = $this->getHelper('question');
            $question = new Question(sprintf('Please enter the %s: ', $optionKey));
            $optionValue = $questionHelper->ask($input$output$question);
        }

        return $optionValue;
    }
}
return $this->askQuestion($question);
    }

    /** * Facade for asking questions * * @return string */
    public function askQuestion(Question $question)
    {
        return $this->IOHelper->ask($question);
    }

    /** * @param string $defaultHostname * * @return string */
    protected function askForDatabaseHostname(
        $defaultHostname
    ) {
        $question = new Question(sprintf('Please enter database host (%s): ', $defaultHostname)$defaultHostname);
        
$env['INSTANCE_ID'] = $this->generateInstanceId();

            $this->createEnvFile($input$io$env);

            return Command::SUCCESS;
        }

        $io->section('Application information');
        $env['APP_ENV'] = $io->choice('Application environment', ['prod', 'dev']$input->getOption('app-env'));

        // TODO: optionally check http connection (create test file in public and request)         $env['APP_URL'] = $io->ask('URL to your /public folder', $input->getOption('app-url')static function Dstring $value): string {
            $value = trim($value);

            if ($value === '') {
                throw new \RuntimeException('Shop URL is required.');
            }

            if (!filter_var($value, \FILTER_VALIDATE_URL)) {
                throw new \RuntimeException('Invalid URL.');
            }

            return $value;
        });
$this->newLine(2);
    }

    public function askQuestion(Question $question): mixed
    {
        if ($this->input->isInteractive()) {
            $this->autoPrependBlock();
        }

        $this->questionHelper ??= new SymfonyQuestionHelper();

        $answer = $this->questionHelper->ask($this->input, $this$question);

        if ($this->input->isInteractive()) {
            if ($this->output instanceof ConsoleSectionOutput) {
                // add the new line of the `return` to submit the input to ConsoleSectionOutput, because ConsoleSectionOutput is holding all it's lines.                 // this is relevant when a `ConsoleSectionOutput::clear` is called.                 $this->output->addNewLineOfInputSubmit();
            }
            $this->newLine();
            $this->bufferedOutput->write("\n");
        }

        
->method('isInteractive')
            ->willReturn(true);
        $input
            ->method('getStream')
            ->willReturn($inputStream);

        $style = new SymfonyStyle($input$output);

        $style->writeln('start');
        $style->write('foo');
        $style->writeln(' and bar');
        $givenAnswer = $style->ask('Dummy question?');
        $style->write('foo2'.\PHP_EOL);
        $output->write('bar2');
        $output->clear();

        rewind($output->getStream());
        $this->assertEquals($answer$givenAnswer);
        $this->assertEquals(escapeshellcmd(
            'start'.\PHP_EOL. // write start             'foo'.\PHP_EOL. // write foo             "\x1b[1A\x1b[0Jfoo and bar".\PHP_EOL. // complete line             \PHP_EOL." \033[32mDummy question?\033[39m:".\PHP_EOL.' > '.\PHP_EOL.\PHP_EOL. // question
/** * {@inheritdoc} */
    protected function configure(): void
    {
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);
        $answer = $io->ask('Are you sure you want to reset the Elasticsearch indexing?', 'yes');

        if ($answer !== 'yes') {
            $io->error('Canceled clearing indexing process');

            return self::SUCCESS;
        }

        $indices = $this->detector->getAllUsedIndices();

        foreach ($indices as $index) {
            $this->client->indices()->delete(['index' => $index]);
        }
$this
            ->addArgument('theme-name', InputArgument::OPTIONAL, 'Theme name');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);
        $themeName = $input->getArgument('theme-name');

        if (!$themeName) {
            $question = new Question('Please enter a theme name: ');
            $themeName = $this->getHelper('question')->ask($input$output$question);
        }

        if (!ctype_upper((string) $themeName[0])) {
            $io->error('The name must start with an uppercase character');

            return self::FAILURE;
        }

        if (preg_match('/^[A-Za-z]\w{3,}$/', (string) $themeName) !== 1) {
            $io->error('Theme name is too short (min 4 characters), contains invalid characters');

            
Home | Imprint | This part of the site doesn't use cookies.