简体   繁体   中英

Calling command asks for interaction even if I have set it to false

Using Symfony 5.4, I have created a command to run several commands (just to refresh my app quickly), here is my code:

    // @see https://symfony.com/doc/current/console/calling_commands.html
    $commands = [
        'doctrine:schema:drop' => [
            '--force' => true,
        ],
        'doctrine:schema:update' => [
            '--force' => true,
        ],
        'doctrine:fixtures:load' => [
            '-n' => true,
            '--group' => ['dev'],
        ],
        'fos:elastica:populate' => []
    ];

    foreach ($commands as $command => $arguments) {
        $output->writeln([
            'Execute command',
            $command,
            '========================',
            '',
        ]);

        $command = $this->getApplication()->find($command);
        $command->run(new ArrayInput($arguments), $output);
    }

It's working fine, except the command doctrine:fixtures:load is asking for:

Careful, database "store" will be purged. Do you want to continue? (yes/no)

I have to set y to continue.

Looking at the help of the command, it seems -n (or --no-interaction ) is what I want, and indeed, launching:

bin/console doctrine:fixtures:load --group=dev -n

manualy works fine.

Why the $arguments are not working for this command? Did I miss something?

Try this:

$nonInteractiveArguments = new ArrayInput($arguments);
$nonInteractiveArguments->setInteractive(false);
$command->run($nonInteractiveArguments, $output);

to set Input interactivity to false.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM