Command chain without prompt to continue

I haven’t found any option to automatically execute several command as a chain without having a prompt to manually confirm to execute the next command.
–no-interaction results in only have the first command executed.

Is there an option i missed out to execute all command without that prompt or is it not possible to run chains unattended?

Have done research here, goggle and haven’t found any solution.

I have not used this yet.

Try setting the --no-interaction parameter for each command in the configuration:

Interesting is, that the question i case of no interaction has the default Y which would be the choice to execute the next command. But the question is never processed.

It looks like chains are only available with human interaction. If the input is not interactive, it never executes the chain.

An excerpt of vendor/laminas/laminas-cli/src/Listener/TerminateListener.php

final class TerminateListener
{
    private const ALLOWED_VENDORS = [
        'laminas',
        'laminas-api-tools',
        'mezzio',
    ];

    private const HOME_PATH_REGEX = '#^(~|\$HOME)#';

    private array $config;

    public function __construct(array $config)
    {
        $this->config = $config;
    }

    public function __invoke(ConsoleTerminateEvent $event): void
    {
        if ($event->getExitCode() !== 0 || ! $event->getInput()->isInteractive()) {
// Here it stops when its not interactive
            return;
        }

        $command = $event->getCommand();
        Assert::isInstanceOf($command, Command::class);

        $class = get_class($command);
        if (
            ! isset($this->config['chains'][$class])
            || ! is_array($this->config['chains'][$class])
        ) {
            return;
        }

        $chain = $this->config['chains'][$class];
        Assert::isMap($chain);

        $commands = $this->config['commands'];
        Assert::isMap($commands);

        $application = $command->getApplication();
        Assert::isInstanceOf($application, Application::class);

        $helper = $application->getHelperSet()->get('question');
        Assert::isInstanceOf($helper, QuestionHelper::class);

        $vendorDir = $this->getVendorDirectory();
        $input     = $event->getInput();
        $output    = $event->getOutput();

// here would be the next chain command executed
        /** @psalm-var array<class-string, string|array> $chain */
        foreach ($chain as $nextCommandClass => $inputMapperSpec) {
            $nextCommandName = array_search($nextCommandClass, $commands, true);
            Assert::string($nextCommandName, sprintf(
                'No command name found for chained command class "%s"; make sure it is defined'
                . ' in the laminas-cli.commands configuration',
                $nextCommandClass
            ));

            $nextCommand       = $application->find($nextCommandName);
            $thirdPartyMessage = $this->matchesApplicationClass($nextCommandClass, $vendorDir)
                ? ''
                : PHP_EOL . '<error>WARNING: This is a third-party command</error>';

            $question = new ChoiceQuestion(
                PHP_EOL . "<info>Executing {$nextCommandName}</info> ({$nextCommand->getDescription()})."
                . $thirdPartyMessage
                . PHP_EOL . '<question>Do you want to continue?</question>',
                ['Y' => 'yes, continue', 's' => 'skip command', 'n' => 'no, break'],
                'Y'
            );

Please create a feature request in the related issue tracker:

Thanks in advance! :+1:t2:

Hope thats ok so:

1 Like