【问题标题】:Calling command asks for interaction even if I have set it to false即使我将其设置为 false,调用命令也会要求交互
【发布时间】:2023-04-10 08:14:01
【问题描述】:

使用 Symfony 5.4,我创建了一个命令来运行多个命令(只是为了快速刷新我的应用程序),这是我的代码:

    // @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);
    }

它工作正常,除了命令doctrine:fixtures:load 要求:

小心,数据库“存储”将被清除。你要继续吗? (是/否)

我必须设置y 才能继续。

查看命令的帮助,似乎-n(或--no-interaction)是我想要的,并且确实正在启动:

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

手动工作正常。

为什么$arguments 不适用于此命令?我错过了什么吗?

【问题讨论】:

  • 这是一种按顺序执行命令的旧方法,您可以使用Make文件请检查此strangebuzz.com/en/snippets/the-perfect-makefile-for-symfony
  • 我同意 CI/CD,我的目标是每次需要在 Elastic 中更新我的固定装置/人口时,无需重新安装项目即可运行一个简单的命令。我们使用它,不回答我的问题

标签: symfony symfony5 symfony-console


【解决方案1】:

试试这个:

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

将输入交互设置为 false。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    相关资源
    最近更新 更多