From 20cdbfe7013cfa79e35261b53f9e246627a0da90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Sun, 26 Mar 2017 16:44:22 -0700 Subject: [PATCH 1/8] Use a git repository for installing plugins. --- .gitignore | 2 +- help.txt | 2 +- lib/commands/plugin-add.sh | 18 +++++++++++++++--- lib/utils.sh | 26 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2f20feee7..251a60c99 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ installs plugins shims +repository .vagrant - diff --git a/help.txt b/help.txt index 13060096d..af104ab75 100644 --- a/help.txt +++ b/help.txt @@ -1,5 +1,5 @@ MANAGE PLUGINS - asdf plugin-add Add git repo as plugin + asdf plugin-add [] Add a plugin asdf plugin-list List installed plugins asdf plugin-remove Remove plugin and package versions asdf plugin-update Update plugin diff --git a/lib/commands/plugin-add.sh b/lib/commands/plugin-add.sh index 459a87801..404e712a5 100644 --- a/lib/commands/plugin-add.sh +++ b/lib/commands/plugin-add.sh @@ -1,11 +1,23 @@ plugin_add_command() { - if [ "$#" -ne 2 ]; then - display_error "usage: asdf plugin-add " + if [[ $# -lt 1 || $# -gt 2 ]]; then + display_error "usage: asdf plugin-add []" 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=$(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 diff --git a/lib/utils.sh b/lib/utils.sh index 411b2fea7..6dc235aed 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -206,3 +206,29 @@ get_asdf_config_value() { get_asdf_config_value_from_file $default_config_path $key fi } + +asdf_repository_url() { + echo "https://github.com/doughsay/asdf-plugins.git" +} + +initialize_or_update_repository() { + local repository_url=$(asdf_repository_url) + local repository_path=$(asdf_dir)/repository + + if [ -d $repository_path ]; then + echo "updating plugin repository..." + (cd $repository_path && git pull) + else + echo "initializing plugin repository..." + git clone $repository_url $repository_path + fi +} + +get_plugin_source_url() { + local plugin_name=$1 + local plugin_config="$(asdf_dir)/repository/plugins/$plugin_name" + + if [ -f $plugin_config ]; then + cat $plugin_config | grep "repository" | awk -F'=' '{print $2}' | sed 's/ //' + fi +} From 96c24e92555c577d489cdb85224ede80bd9be8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Wed, 19 Apr 2017 20:26:33 -0700 Subject: [PATCH 2/8] code review feedback: git reset instead of git pull --- lib/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.sh b/lib/utils.sh index 6dc235aed..9e63171bc 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -217,7 +217,7 @@ initialize_or_update_repository() { if [ -d $repository_path ]; then echo "updating plugin repository..." - (cd $repository_path && git pull) + (cd $repository_path && git fetch && git reset --hard origin/master) else echo "initializing plugin repository..." git clone $repository_url $repository_path From f399254219e27e3ecc35b10c5f98e0b80e516010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Wed, 19 Apr 2017 20:37:03 -0700 Subject: [PATCH 3/8] code review feedback: fix all shellcheck warnings. --- lib/commands/plugin-add.sh | 3 ++- lib/utils.sh | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/commands/plugin-add.sh b/lib/commands/plugin-add.sh index 404e712a5..93ec606c3 100644 --- a/lib/commands/plugin-add.sh +++ b/lib/commands/plugin-add.sh @@ -10,7 +10,8 @@ plugin_add_command() { local source_url=$2 else initialize_or_update_repository - local source_url=$(get_plugin_source_url $plugin_name) + local source_url + source_url=$(get_plugin_source_url "$plugin_name") fi if [ -z "$source_url" ]; then diff --git a/lib/utils.sh b/lib/utils.sh index 9e63171bc..87871a1fa 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -212,23 +212,30 @@ asdf_repository_url() { } initialize_or_update_repository() { - local repository_url=$(asdf_repository_url) - local repository_path=$(asdf_dir)/repository + local repository_url + local repository_path - if [ -d $repository_path ]; then + 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) + (cd "$repository_path" && git fetch && git reset --hard origin/master) else echo "initializing plugin repository..." - git clone $repository_url $repository_path + git clone "$repository_url" "$repository_path" fi } get_plugin_source_url() { - local plugin_name=$1 - local plugin_config="$(asdf_dir)/repository/plugins/$plugin_name" + local plugin_name + local plugin_config + + plugin_name=$1 + plugin_config="$(asdf_dir)/repository/plugins/$plugin_name" + - if [ -f $plugin_config ]; then - cat $plugin_config | grep "repository" | awk -F'=' '{print $2}' | sed 's/ //' + if [ -f "$plugin_config" ]; then + grep "repository" "$plugin_config" | awk -F'=' '{print $2}' | sed 's/ //' fi } From 5255f0e664146dac4525fc67915d24ddeb2b420d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Wed, 19 Apr 2017 20:40:06 -0700 Subject: [PATCH 4/8] a little too zealous on the shellcheck warnings. --- lib/utils.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/utils.sh b/lib/utils.sh index 87871a1fa..df6957302 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -228,10 +228,9 @@ initialize_or_update_repository() { } get_plugin_source_url() { - local plugin_name + local plugin_name=$1 local plugin_config - plugin_name=$1 plugin_config="$(asdf_dir)/repository/plugins/$plugin_name" From a4fed4e4cd1db9cb058949648b3388ca36e66fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Sun, 23 Jul 2017 09:34:58 -0700 Subject: [PATCH 5/8] Add simple test for plugin-add command. --- test/plugin_commands.bats | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/plugin_commands.bats diff --git a/test/plugin_commands.bats b/test/plugin_commands.bats new file mode 100644 index 000000000..cbc61f642 --- /dev/null +++ b/test/plugin_commands.bats @@ -0,0 +1,22 @@ +#!/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" ] +} From 23f767c624b26f3f04d778f5631b1ee79c3ea2f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Tue, 25 Jul 2017 17:03:30 -0700 Subject: [PATCH 6/8] Add test for bad plugin name case. --- test/plugin_commands.bats | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/plugin_commands.bats b/test/plugin_commands.bats index cbc61f642..651023877 100644 --- a/test/plugin_commands.bats +++ b/test/plugin_commands.bats @@ -20,3 +20,9 @@ teardown() { 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" +} From 1bdaf22a3656615d7d1df9e6c3141301575156be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Tue, 25 Jul 2017 17:15:08 -0700 Subject: [PATCH 7/8] Update README and creating-pugins doc to reflect new plugin-add command. --- README.md | 11 +++++++++-- docs/creating-plugins.md | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index edd65ce03..3937f5797 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 +# 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 -# 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 diff --git a/docs/creating-plugins.md b/docs/creating-plugins.md index bae5e0bc1..0e34f7617 100644 --- a/docs/creating-plugins.md +++ b/docs/creating-plugins.md @@ -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). From a0e5573960a315ce2ca4b56bfc0771488f07141b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Dos=C3=A9?= Date: Wed, 26 Jul 2017 09:20:05 -0700 Subject: [PATCH 8/8] Update plugins repo url. --- lib/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.sh b/lib/utils.sh index df6957302..6afa3460b 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -208,7 +208,7 @@ get_asdf_config_value() { } asdf_repository_url() { - echo "https://github.com/doughsay/asdf-plugins.git" + echo "https://github.com/asdf-vm/asdf-plugins.git" } initialize_or_update_repository() {