wp-cli / ideas

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

Identify alias type (singleton or group) #173

Closed baizmandesign closed 1 year ago

baizmandesign commented 1 year ago

Feature Request

Describe your use case and the problem you are facing

I'd like to be able to differentiate between the two types of WP CLI aliases: ones that resolve to a single site's definition (which we'll call a "singleton" alias), and ones that resolve to one or more aliases (which we'll call a "group" alias). This would be useful for scripting purposes.

An example might help. Let's say that I have the following aliases:

@one:
     ssh: one.org
     path: public_html

@two:
     ssh: two.org
     path: public_html

@both:
 - @one
 - @two

Now let's say that one is a single instance of WordPress, and two is a multi-site instance of WordPress. There are a number of commands that require an extra flag to work on a multi-site ("--network"). For example, activating a plugin. The following command will succeed for "one" and fail for "two":

$ wp @both plugin activate some-plugin

It fails for "two" because it lacks the "--network" flag.

Describe the solution you'd like

I know I can use the shell and grep to address this problem, but it would be nice if it were addressed in WP CLI itself.

I have one proposal in two flavors: create a new command to determine whether an alias is a group: wp cli alias is-group (returns 0 on true, 1 on false). This is similar to other commands such as wp core is-installed or wp plugin is-active). Or wp cli alias get-type (returns string "group" or "single"). With this command in a script, some conditional processing can be done when dealing with either a singleton or group alias.

danielbachhuber commented 1 year ago

Thanks for the suggestion, @baizmandesign !

create a new command to determine whether an alias is a group: wp cli alias is-group (returns 0 on true, 1 on false).

I'd be open to this if you'd like to submit a pull request for it.

baizmandesign commented 1 year ago

@danielbachhuber Sounds good! I'll cook up a PR shortly.

danielbachhuber commented 1 year ago

🚢 https://github.com/wp-cli/wp-cli/pull/5766