Add runtime_args to options array for runcommand#5722
Add runtime_args to options array for runcommand#5722schlessera merged 5 commits intowp-cli:mainfrom
Conversation
danielbachhuber
left a comment
There was a problem hiding this comment.
Tests should be great, thanks! features/runcommand.feature would be a good place for them.
I added a test. I wasn't familiar with behat before this so any suggestions welcome. |
|
While working on this I was thinking another helpful feature might be to include the full command run as part of the object returned here: Lines 1402 to 1405 in 187eda2 So there would be a way to see what this was: Line 1335 in 187eda2 Right now I don't think there is a way to see the full command that is run? |
schlessera
left a comment
There was a problem hiding this comment.
I'm not very fond of the name runtime_args. This would imply we need to distinguish them from compile-time arguments, which we don't have. Everything that happens here is runtime anyway.
How about command_args to distinguish them from the method arguments?
Sounds good, updated! |
Allow a caller to pass runtime arguments to WP_CLI::runcommand so that it is possible to store all 'default' options in one place. ex if you want to avoid plugins and themes per default in a script that calls runcommand a lot: ``` $default_cli_opts = array( 'return' => 'all', 'exit_error' => false, 'runtime_args' => array( '--skip-themes', '--skip-plugins' ), ); $output = WP_CLI::runcommand( 'option get siteurl', $default_cli_opts); ```
Co-authored-by: Alain Schlesser <alain.schlesser@gmail.com>
|
Thanks for the PR, @mrsdizzie ! |
Per https://wordpress.slack.com/archives/C02RP4T41/p1673268015148999?thread_ts=1672934225.683679&cid=C02RP4T41
I have a command that calls
WP_CLI::runcommanda lot and I want to set some default global options for most of these (particularly--skip-themes --skip-plugins). I also have default global options forWP_CLI::runcommanditself.Currently, this ends up looking something like:
It would be nice to be able to keep these options in a single place like:
This PR just appends the options to the command as if the caller included them in the command directly.
I didn't see any place that runcommand was tested as if being called from a script so I wasn't sure where/how to add a test for this as it isn't accessible when using wp-cli directly. Happy to add one though