mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Merge pull request #183 from doughsay/master
Use a git repository for installing plugins.
This commit is contained in:
commit
78fbbaf584
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,5 @@
|
||||
installs
|
||||
plugins
|
||||
shims
|
||||
repository
|
||||
.vagrant
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
help.txt
2
help.txt
@ -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
|
||||
|
@ -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
|
||||
|
32
lib/utils.sh
32
lib/utils.sh
@ -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
test/plugin_commands.bats
Normal file
28
test/plugin_commands.bats
Normal file
@ -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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user