-
Notifications
You must be signed in to change notification settings - Fork 998
Add runtime_args to options array for runcommand #5722
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor cosmetic changes.
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::runcommand
a 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::runcommand
itself.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