add a `--skip-plugins-except=<plugins-to-keep-active>` global parameter
pbiron opened this issue · comments
Feature Request
- Yes, I reviewed the contribution guidelines.
Describe your use case and the problem you are facing
When doing wp @foo export --filename_format=file.xml --post_type=my-cpt
I usually want to skip all plugins except for the plugin that registers my-cpt
and when doingwp @bar import file.xml
(where file.xml contains posts of post_type my-cpt
) I usually want to skip all plugins except for wordpress-importer
and the plugin that registers my-cpt
.
In such cases, I turn to various "shell friends" to accomplish this, but I always have to rack my brain to remember exactly the syntax to use in those shell friends:
wp @foo export --filename_format=file.xml --post-type=my-cpt --skip-plugins=$(wp @foo plugin list --field=name --status=active | grep -v my-plugin | paste -s -d ",")
wp @bar import file.xml --skip-plugins=$(wp @bar plugin list --field=name --status=active | grep -vE 'wordpress-importer|my-plugin' | paste -s -d ",")
Describe the solution you'd like
I propose adding a new global parameter: --skip-plugins-except=<plugins-to-keep-active>
, where <plugins-to-keep-active>
is a comma-separate list of plugin slugs.
With this new global parameter, the above commands could be simplified to:
wp @foo export --filename_format=file.xml --post-type=my-cpt --skip-plugins-except=my-plugin
wp @bar import file.xml --skip-plugins-except=wordpress-importer,my-plugin
This new global parameter would have many benefits:
- makes the intent much more clear (i.e., self-documenting)
- opens the functionality to more users (e.g., those who aren't comfortable with complex shell commands)
- opens the functionality to environments where typical shell friends aren't available (e.g., Windows)
For completeness, it would probably also be a good idea to add --skip-themes-except=<themes-to-keep-active>
, even though I can't at the moment think of any reasonable use cases where I'd want to, say, skip a child theme while leaving the parent theme active...but such use cases could exist.
Although, I haven't yet checked how the existing --skip-plugins
(and --skip-themes
) parameters are implemented, I think it should be relatively easy to add this new functionality, altho there might be a few corner cases that need to be considered, e.g., #3827.
Something which should be discussed before jumping in with a proposed patch is: what should happen if the plugins specified in --skip-plugins-except=<plugins-to-keep-active>
are not currently active?
A couple of options come to mind:
- silently ignore the "user error" (which is essentially what happens with the
--skip-plugins + shell friends
approach) - temporarily activate those plugins that aren't already active (if they are installed)
- exit with an error (to let the user know that their intent can't be realized)
There are probably other others as well.
Thanks for the suggestion, @pbiron
Because global parameters conflict with local parameters, I think it's very unlikely we will add any new ones. While it seems unlikely, we could break someone's existing command.
It could be worth exploring other ways of achieving this same goal, though.
Because global parameters conflict with local parameters...
Can you elaborate on this.
I think you're saying that there is a possibility that --skip-plugins-except=<plugins-to-keep-active>
could conflict with the --<field>=<value>
parameter of the wp post list
command (and similar "dynamic" local parameters of other commands). Is that what you're getting at?
@pbiron Someone could have developed a custom command with a --skip-plugins-except
parameter. If we now add such a global parameter in WP-CLI, we would break their command. Hope that clarifies it!
Related: the proposed --skip-plugins-except
param reminds me a bit of troubleshooting mode in the Health Check & Troubleshooting plugin
@pbiron Someone could have developed a custom command with a
--skip-plugins-except
parameter. If we now add such a global parameter in WP-CLI, we would break their command. Hope that clarifies it!
Yes, it does, thanx, Pascal. I can understand why adding new global params might be a bad thing
In such cases, I turn to various "shell friends" to accomplish this, but I always have to rack my brain to remember exactly the syntax to use in those shell friends:
wp @foo export --filename_format=file.xml --post-type=my-cpt --skip-plugins=$(wp @foo plugin list --field=name --status=active | grep -v my-plugin | paste -s -d ",")
wp @bar import file.xml --skip-plugins=$(wp @bar plugin list --field=name --status=active | grep -vE 'wordpress-importer|my-plugin' | paste -s -d ",")
Perhaps we could add a new --exclude
param to wp plugin list
? That would make this a bit easier.
e.g. wp @bar import file.xml --skip-plugins=$(wp @bar plugin list --field=name --status=active --exclude=wordpress-importer,my-plugin)
Thoughts?
It could be worth exploring other ways of achieving this same goal, though.
Just spitballing here, but maybe we could introduce new syntax for the existing --skip-plugins
param, such as:
wp @foo export --filename_format=file.xml --post-type=my-cpt --skip-plugins=!my-plugin
Altho, it's probably possible that a real plugin slug could begin with !
A similar suggestion would be to use !=
, as in:
wp @foo export --filename_format=file.xml --post-type=my-cpt --skip-plugins!=my-plugin
Another idea I just thought of is to "co-opt" the --no-
flag prefix (e.g., as in wp command --no-color
) which might become:
wp @foo export --filename_format=file.xml --post-type=my-cpt --no-skip-plugins=my-plugin
that one's a stretch ;-) Like I said, just throwing out ideas
Perhaps we could add a new
--exclude
param towp plugin list
? That would make this a bit easier.e.g.
wp @bar import file.xml --skip-plugins=$(wp @bar plugin list --field=name --status=active --exclude=wordpress-importer,my-plugin)
That would work...if we can't come up with better strategy
In general, I think having a way to negate --param=val
parameters would be great.
For instance, I occasionally would like get a list of plugins that do not have --status=inactive
and there is currently no way to do that (without resorting to shell friends). So, having something like:
wp plugin list --status!=inactive
could come in handy
Perhaps we could add a new
--exclude
param towp plugin list
? That would make this a bit easier.
e.g.wp @bar import file.xml --skip-plugins=$(wp @bar plugin list --field=name --status=active --exclude=wordpress-importer,my-plugin)
That would work...if we can't come up with better strategy
I'd also note that having a "negation" syntax would obviate the need for a new --exclude
param for wp plugin list
, because then we could do
wp plugin list --name!=wordpress-importer,my-plugin
(with whatever negation syntax we come up)
The negation syntax is tempting...
But there are certainly params that it should not be allowed on because of the semantics. For example, wp plugin list --format!=table
;-)