wp-cli / extension-command

Manages plugins and themes, including installs, activations, and updates.
MIT License
89 stars 80 forks source link

Allow `--format` option in `wp theme mod set` #86

Open selrond opened 6 years ago

selrond commented 6 years ago

Is it possible to set formatted theme_mods in wp theme mod set the same way it's possible to get them through wp theme mod get <mod> --format=json?

It'd be really useful for bulk editing theme_mods and importing them in one command instead of in current one-by-one fashion - wp theme mod set <mod> <value>

danielbachhuber commented 6 years ago

Thanks for the suggestion, @selrond.

Something like wp theme mod set would be closest syntactically to wp option set, which supports --format=json to accept some array of data for the option. It doesn't set all options, only the value for the specific option.

I think yours is a reasonable suggestion, but we'd probably want to create a new command for it. wp theme mod import could be one option.

selrond commented 6 years ago

@danielbachhuber while wp theme mod import sounds good, I think more versatile approach would be to implement something link pluck & patch commands as seen in wp option pluck or wp option patch.

So having theme mod pluck or theme mod patch would be good, flexible (although I'm not sure how many levels deep can you go with pluck command or if it's even possible to go down more than 1 level), and even naming would be consistent with already present implementations:

danielbachhuber commented 6 years ago

theme mod pluck and theme mod patch both seem like reasonable additions, although they would only permit manipulation of individual mods. My initial understanding was that you wanted to access or update all mods at once?

selrond commented 6 years ago

@danielbachhuber True, but only because I didn't yet know about pluck and patch.

So all in all, both usecases are still valid.

What do you think?

danielbachhuber commented 6 years ago

If you want to bulk change all mods, then we'd need theme mod import. theme mod set is only for an individual mod.

Everything else seems reasonable though.

selrond commented 6 years ago

Right, but I't looks a bit weird having

Name Description
wp theme mod get Gets one or more theme mods.
wp theme mod remove Removes one or more theme mods.
wp theme mod set Sets the value of a theme mod.

(from wp theme mod | WordPress Developer Resources)

Wouldn't it make sense instead to extend existing theme mod set with --format option like it's possible and already present here wp option add --format=json?

danielbachhuber commented 6 years ago

Wouldn't it make sense instead to extend existing theme mod set with --format option like it's possible and already present here wp option add --format=json?

No, because theme mod set is meant to act upon an individual theme mod. option add --format=json only acts upon an individual option; it doesn't update all options when you use the --format=json flag.