Skip to content

Commit

Permalink
Merge pull request #183 from doughsay/master
Browse files Browse the repository at this point in the history
Use a git repository for installing plugins.
  • Loading branch information
Daniel Perez authored Jul 26, 2017
2 parents 01bb9ac + a0e5573 commit 78fbbaf
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 6 deletions.
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

9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,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
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 @@ -260,3 +260,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"
}

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"
}

0 comments on commit 78fbbaf

Please sign in to comment.