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

Use a git repository for installing plugins. #183

Merged
merged 8 commits into from
Jul 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
installs
plugins
shims
repository
.vagrant

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mkdir -p ~/.config/fish/completions; and cp ~/.asdf/completions/asdf.fish ~/.con
Plugins are how asdf understands how to handle different packages. Below is a list of plugins for languages. There is a [super-simple API](https://github.com/asdf-vm/asdf/blob/master/docs/creating-plugins.md) for supporting more languages.

| Language | Repository | CI Status
|-----------|-------------|----------
|-----------|-------------|----------
| Clojure | [vic/asdf-clojure](https://github.com/vic/asdf-clojure) | [![Build Status](https://travis-ci.org/vic/asdf-clojure.svg?branch=master)](https://travis-ci.org/vic/asdf-clojure)
| Crystal | [marciogm/asdf-crystal](https://github.com/marciogm/asdf-crystal) | [![Build Status](https://travis-ci.org/marciogm/asdf-crystal.svg?branch=master)](https://travis-ci.org/marciogm/asdf-crystal)
| D (DMD) | [sylph01/asdf-dmd](https://github.com/sylph01/asdf-dmd) | [![Build Status](https://travis-ci.org/sylph01/asdf-dmd.svg?branch=master)](https://travis-ci.org/sylph01/asdf-dmd)
Expand Down Expand Up @@ -82,9 +82,16 @@ Plugins are how asdf understands how to handle different packages. Below is a li

##### Add a plugin

```bash
asdf plugin-add <name>
# asdf plugin-add erlang
```

If the plugin you want to install is not part of the official plugins list, you can add it using its repository URL:

```bash
asdf plugin-add <name> <git-url>
# asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git
# asdf plugin-add elm https://github.com/vic/asdf-elm
```

##### List installed plugins
Expand Down
8 changes: 8 additions & 0 deletions docs/creating-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ os:
- linux
- osx
```

## Submitting plugins to the official plugins repository

`asdf` can easily install plugins by specifying the plugin repository url, e.g. `plugin-add my-plugin https://github.com/user/asdf-my-plugin.git`.

To make it easier on your users, you can add your plugin to the official plugins repository to have your plugin listed and easily installable using a shorter command, e.g. `asdf plugin-add my-plugin`.

Follow the instruction at the plugins repository: [asdf-vm/asdf-plugins](https://github.com/asdf-vm/asdf-plugins).
2 changes: 1 addition & 1 deletion help.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MANAGE PLUGINS
asdf plugin-add <name> <git-url> Add git repo as plugin
asdf plugin-add <name> [<git-url>] Add a plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the help message here should be a little more detailed. Perhaps something like Add a plugin from the plugin repo OR add a Git repo as a plugin by specifying name and repo url?

asdf plugin-list List installed plugins
asdf plugin-remove <name> Remove plugin and package versions
asdf plugin-update <name> Update plugin
Expand Down
19 changes: 16 additions & 3 deletions lib/commands/plugin-add.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
plugin_add_command() {
if [ "$#" -ne 2 ]; then
display_error "usage: asdf plugin-add <name> <git-url>"
if [[ $# -lt 1 || $# -gt 2 ]]; then
display_error "usage: asdf plugin-add <name> [<git-url>]"
exit 1
fi

local plugin_name=$1
local source_url=$2

if [ -n "$2" ]; then
local source_url=$2
else
initialize_or_update_repository
local source_url
source_url=$(get_plugin_source_url "$plugin_name")
fi

if [ -z "$source_url" ]; then
display_error "plugin $plugin_name not found in repository"
exit 1
fi

local plugin_path=$(get_plugin_path $plugin_name)

mkdir -p $(asdf_dir)/plugins
Expand Down
32 changes: 32 additions & 0 deletions lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,35 @@ get_asdf_config_value() {
get_asdf_config_value_from_file $default_config_path $key
fi
}

asdf_repository_url() {
echo "https://github.com/asdf-vm/asdf-plugins.git"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this to the top of the file under the asdf_version function since it's basically a constant.


initialize_or_update_repository() {
local repository_url
local repository_path

repository_url=$(asdf_repository_url)
repository_path=$(asdf_dir)/repository

if [ -d "$repository_path" ]; then
echo "updating plugin repository..."
(cd "$repository_path" && git fetch && git reset --hard origin/master)
else
echo "initializing plugin repository..."
git clone "$repository_url" "$repository_path"
fi
}

get_plugin_source_url() {
local plugin_name=$1
local plugin_config

plugin_config="$(asdf_dir)/repository/plugins/$plugin_name"


if [ -f "$plugin_config" ]; then
grep "repository" "$plugin_config" | awk -F'=' '{print $2}' | sed 's/ //'
fi
}
28 changes: 28 additions & 0 deletions test/plugin_commands.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bats

load test_helpers

. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-add.sh
. $(dirname $BATS_TEST_DIRNAME)/lib/commands/plugin-list.sh

setup() {
setup_asdf_dir
}

teardown() {
clean_asdf_dir
}

@test "plugin_add command with no URL specified adds a plugin using repo" {
run plugin_add_command "elixir"
[ "$status" -eq 0 ]

run plugin_list_command
[ "$output" = "elixir" ]
}

@test "plugin_add command with no URL specified fails if the plugin doesn't exist" {
run plugin_add_command "does-not-exist"
[ "$status" -eq 1 ]
echo "$output" | grep "plugin does-not-exist not found in repository"
}