Skip to content
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

Identify alias type (singleton or group) #173

Closed
1 task done
baizmandesign opened this issue Apr 3, 2023 · 3 comments
Closed
1 task done

Identify alias type (singleton or group) #173

baizmandesign opened this issue Apr 3, 2023 · 3 comments

Comments

@baizmandesign
Copy link

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
Copy link
Member

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
Copy link
Author

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

@danielbachhuber
Copy link
Member

🚢 wp-cli/wp-cli#5766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants