8000 Plugins - Add 'basic-alias' and 'alias-cmd' to cv.phar by totten · Pull Request #240 · civicrm/cv · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Plugins - Add 'basic-alias' and 'alias-cmd' to cv.phar #240

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

Merged
merged 11 commits into from
Feb 28, 2025

Conversation

totten
Copy link
Member
@totten totten commented Feb 20, 2025

Overview

Site aliases allow you to run a cv subcommand on a particular site without manually navigating through the filesystem. Compare:

## Use an alias
cv @wombat api4 Contact.get

## Or... explicitly navigate the filesystem
cd /home/myuser/projects/wombat.org/web && cv api4 Contact.get

## Or... explicitly navigate SSH+filesystem and set various boot options
ssh server.wombat.org
cd /home/myuser/projects/wombat.org/web
cv api4 Contact.get \
  --url='https://www.wombat.org/' \
  --level=cms-first \
  --user=admin

In the first example, it uses an alias (@wombat). The alias can define all these other options (path, URL, etc) so that you don't need to type them into every command.

This functionality was previously demonstrated by implementing the basic-alias plugin that was published via gist, but this is fairly obscure. This PR adds basic-alias plugin as a built-in feature, and it also introduces a complementary plugin (alias-cmd) for managing aliases via CLI.

Before

  • You can manually construct commands with notes about bootstrap (re: cd, --cwd, --user, --url, etc).

  • You can download the alias plugin and create alias-files by hand.

After

There is a built-in alias-plugin and helper commands.

To define a new alias, run the alias:add command:

## Start an interactive questionnaire
$ cv alias:add

## As above, but pre-fill some of the answers
$ cv alias:add wpmaster /var/www/wpmaster/web

This will ask questions about remote (SSH), multisite (base URL), default user-name, etc. It will ultimately create a file (such as $HOME/.cv/alias/wpmaster.json).

Similarly, you can browse available aliases:

cv alias:list
+----------+-------+---------------------------------------+
| name     | type  | config                                |
+----------+-------+---------------------------------------+
| dmaster  | basic | /Users/totten/.cv/alias/dmaster.json  |
| wpmaster | basic | /Users/totten/.cv/alias/wpmaster.json |
+----------+-------+---------------------------------------+

Finally, you can run commands with the alias, as in:

cv @wpmaster status
cv @wpmaster ext:list -Li

Comments

There's a sample build at https://think.hm/tmp/cv-aliases-2025-02-26-0.phar.

The general reason why basic-alias is a plugin is that it would be handy to make new variations on the functionality. There's a lot of subjectivity in what features should be provided for aliases. For example:

  • If you use civibuild, then you might want to automatically recognize aliases for all BUILDKIT/build/*.sh files.
  • If you want contextual aliases within a build (@staging, @prod), then you need to seek-out a context-sensitive config-file.

In any case, the absence of a reference-implementation makes the whole thing seem esoteric.

With this approach, we can kind of have it both ways:

  • There is a default/out-of-the-box/concrete option for site-aliases.
  • The default option is structured as a plugin -- so the wiring is plugin-friendly, and it can be adapted to other techniques.

@totten totten force-pushed the master-plugin-alias branch from a66c7c0 to 592042f Compare February 26, 2025 09:41
It's a little bit magical to link CV_PLUGIN_PATH to the aliases-list.

We can reassess whether this should be more magical when someone actually
has a use-case.
Based on similar searches elsewhere...
@totten
Copy link
Member Author
totten commented Feb 28, 2025

Well, got a +1 on chat, and yolo

@totten totten merged commit e1f3ca1 into civicrm:master Feb 28, 2025
1 check passed
@totten totten deleted the master-plugin-alias branch February 28, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0