wp-cli / ideas

💡 Ideas and feature requests are collected here
40 stars 1 forks source link

Provide a CLI option to run multiple commands in one process. #180

Open toddr opened 9 months ago

toddr commented 9 months ago

Feature Request

Describe your use case and the problem you are facing

I would like a "multi" option that would allow me to run multiple CLI commands in one process, speeding up overall execution time.

Describe the solution you'd like

The option would use STDIN or possibly a data file that lists the commands we want to run all at once.

A draft idea might be something like this.

echo 'set options blogname "my title"' > commands.txt
echo 'set options blogdescription "my description"' >> commands.txt
echo 'core update' >> commands.txt
wp-cli --json runcommands << commands.txt

I'd also be open to some complex command line only option like this. The only problem with this is that CLI would have to convert the args into individual commands, splitting on space.

wp-cli --json multi 'set options blogname "my title"' 'set options blogdescription "my description"'  
'core update'

This command would come with a caveat emptor warning that each command may have unexpected side effects on the later commands and anyone using it needs to be certain that it won't affect them to run it all in one process without flush or refresh.

In my above example, I would be required to know that messing with blogname/description will not have side effects on each other and that the update would be fine following the first 2.

If we wanted to get fancy, maybe we'd add a flush option that would invalidate caches if needed as you go?

The JSON result might provide an array of responses from each command.

danielbachhuber commented 9 months ago

Thanks for the suggestion, @toddr !

I think this would be best implemented as a standalone package first. It could be considered for including in WP-CLI proper once the real-world idiosyncrasies have been worked out.