Use a git repository for installing plugins.

This commit is contained in:
Chris Dosé 2017-03-26 16:44:22 -07:00
parent 68d759b5d8
commit 20cdbfe701
No known key found for this signature in database
GPG Key ID: 293B1FFF4E41BB4A
4 changed files with 43 additions and 5 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
installs
plugins
shims
repository
.vagrant

View File

@ -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

View File

@ -1,11 +1,23 @@
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=$(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

View File

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