mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 09:38:16 -07:00
57186be6d9
* Add support for custom `plugin-add` and `plugin-remove` in plugins * Add configurable command hooks for plugin installation and removal ```shell pre_asdf_plugin_remove = echo will remove plugin ${1} pre_asdf_plugin_remove_foo = echo will remove plugin foo post_asdf_plugin_remove = echo removed plugin ${1} post_asdf_plugin_remove_foo = echo removed plugin foo ``` Closes #670
54 lines
1.2 KiB
Bash
54 lines
1.2 KiB
Bash
# -*- sh -*-
|
|
|
|
plugin_add_command() {
|
|
if [[ $# -lt 1 || $# -gt 2 ]]; then
|
|
display_error "usage: asdf plugin-add <name> [<git-url>]"
|
|
exit 1
|
|
fi
|
|
|
|
local plugin_name=$1
|
|
|
|
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
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
|
|
|
mkdir -p "$(asdf_data_dir)/plugins"
|
|
|
|
if [ -d "$plugin_path" ]; then
|
|
display_error "Plugin named $plugin_name already added"
|
|
exit 2
|
|
else
|
|
asdf_run_hook "pre_asdf_plugin_add" "$plugin_name"
|
|
asdf_run_hook "pre_asdf_plugin_add_${plugin_name}"
|
|
|
|
if ! git clone -q "$source_url" "$plugin_path"; then
|
|
exit 1
|
|
fi
|
|
|
|
if [ -f "${plugin_path}/bin/plugin-add" ]; then
|
|
(
|
|
export ASDF_PLUGIN_SOURCE_URL=$source_url
|
|
export ASDF_PLUGIN_PATH=$plugin_path
|
|
bash "${plugin_path}/bin/plugin-add"
|
|
)
|
|
fi
|
|
|
|
asdf_run_hook "post_asdf_plugin_add" "$plugin_name"
|
|
asdf_run_hook "post_asdf_plugin_add_${plugin_name}"
|
|
fi
|
|
}
|
|
|
|
plugin_add_command "$@"
|