2015-05-17 11:20:51 -07:00
|
|
|
plugin_add_command() {
|
2017-03-26 16:44:22 -07:00
|
|
|
if [[ $# -lt 1 || $# -gt 2 ]]; then
|
|
|
|
display_error "usage: asdf plugin-add <name> [<git-url>]"
|
2016-07-03 04:11:40 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-05-26 23:43:26 -07:00
|
|
|
local plugin_name=$1
|
2017-03-26 16:44:22 -07:00
|
|
|
|
|
|
|
if [ -n "$2" ]; then
|
|
|
|
local source_url=$2
|
|
|
|
else
|
|
|
|
initialize_or_update_repository
|
2017-04-19 20:37:03 -07:00
|
|
|
local source_url
|
|
|
|
source_url=$(get_plugin_source_url "$plugin_name")
|
2017-03-26 16:44:22 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$source_url" ]; then
|
|
|
|
display_error "plugin $plugin_name not found in repository"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
2015-05-17 11:20:51 -07:00
|
|
|
|
2018-06-10 01:54:39 -07:00
|
|
|
mkdir -p "$(asdf_data_dir)/plugins"
|
2015-06-15 05:59:27 -07:00
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
if [ -d "$plugin_path" ]; then
|
2016-07-03 04:11:40 -07:00
|
|
|
display_error "Plugin named $plugin_name already added"
|
2018-05-29 19:47:46 -07:00
|
|
|
exit 2
|
2015-06-15 05:59:27 -07:00
|
|
|
else
|
2017-09-04 10:04:56 -07:00
|
|
|
if ! git clone "$source_url" "$plugin_path"; then
|
2016-05-13 00:04:01 -07:00
|
|
|
exit 1
|
2015-06-15 05:59:27 -07:00
|
|
|
fi
|
2015-05-17 11:20:51 -07:00
|
|
|
fi
|
|
|
|
}
|