Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli command chain without interaction #123

Open
sbo-develop opened this issue Apr 25, 2024 · 3 comments
Open

Cli command chain without interaction #123

sbo-develop opened this issue Apr 25, 2024 · 3 comments

Comments

@sbo-develop
Copy link

Feature Request

Command chains are not possible to run without interaction. Chains are only available with human interaction. If the input is not interactive, it never executes the chain.

This listener is stopping when the input isn't interactive:
vendor/laminas/laminas-cli/src/Listener/TerminateListener.php
public function __invoke(ConsoleTerminateEvent $event): void { if ($event->getExitCode() !== 0 || ! $event->getInput()->isInteractive()) { // Here it stops when its not interactive return; }

Q A
New Feature yes
RFC no
BC Break no

Summary

Execute command chains without interaction, maybe with a --force-chain-execution parameter to not change the past behaviour.

@froschdesign
Copy link
Member

@michalbundyra
Can you please have a look at the problem?
Thanks in advance! 👍🏻

@michalbundyra
Copy link
Member

@sbo-develop @froschdesign

I was looking into it. Here is the original PR: #19 with the chain feature.

I do not remember exactly why we did not allow non-interactive mode with chains, but I guess it was due to 'security'.
That's why we added prompts to check if you'd like to run the next command in the chain, and a warning if the command you are about to run is a 3rd part command.

I was checking and we can potentially drop the condition you have noted @sbo-develop, but I believe it would be a BC Break.

The other option we can do, we can provide a new configuration option (which will be default to false) something like allow_non_interactive_chains. But then I started thinking - ok, if we have this maybe it should not be just bool, but you should be able to decide if you want to allow 3rd-party commands as well or not (so: 0 - disabled, 1 - just own + laminas commands, 2 - everything).

The other feature might be to introduce one more configuration - to specify a whitelist of the namespaces we allow commands from.

Also, current behaviour in non-interactive mode is that we break after first command and do not execute any chained commands. If we change it to run automatically all other commands I believe we should have also an option to "skip chain". Let see the example - we have two commands:

1. first-command
2. second-command

the chain is defined that first-command => second-command

so now (when it is not possible to run chains in non-interactive mode) we get:

bin/laminas first-command --no-interaction

will run JUST first-command and it will stop.

If we allow chained runs in non-interactive then both commands will be executed.
So we would need to have an ability to 'revert the future' from the cli, for example:

bin/laminas first-command --no-chain --no-interaction

And it makes me to the point, that maybe allowing chain in non interactive mode should be a separate argument?
So if we want to execute all chained commands in non-interactive mode we would need to do:

bin/laminas first-command --with-chain --no-interaction

or even we can implement it as argument with some options (just local command, also 3rd part or whitelisted ...).

As the feature seems to be quite nice and easy, I believe we should take it all into consideration to make a right decision. And at the end document it well, so it is easy to use. Now I am on the side that chain should not be called automatically on non-interactive mode, unless user opted-in in the config.

Hope it all makes any sense :)

@sbo-develop
Copy link
Author

Very well thought through answer. I‘m with you to have it with opt in and configurable ( former behavior must be kept the same ). An additional parameter with default execute all, except you choose otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants