Merge pull request #273 from jthegedus/show-url-current-v Add print repo URLs with asdf plugin-list and adsf plugin-list-all

This commit is contained in:
Daniel Perez 2018-01-31 02:00:08 +09:00 committed by Trevor Brown
commit da966827f0
7 changed files with 69 additions and 21 deletions

View File

@ -92,6 +92,15 @@ asdf plugin-add <name> <git-url>
```bash
asdf plugin-list
# asdf plugin-list
# java
# nodejs
```
```bash
asdf plugin-list --urls
# asdf plugin-list
# java https://github.com/skotchpine/asdf-java.git
# nodejs https://github.com/asdf-vm/asdf-nodejs.git
```
##### Remove a plugin

View File

@ -2,7 +2,8 @@ MANAGE PLUGINS
asdf plugin-add <name> [<git-url>] Add a plugin from the plugin repo OR, add a Git repo
as a plugin by specifying the name and repo url
asdf plugin-list List installed plugins
asdf plugin-list-all List plugins registered on asdf-plugins repository
asdf plugin-list --urls List installed plugins with repository URLs
asdf plugin-list-all List plugins registered on asdf-plugins repository with URLs
asdf plugin-remove <name> Remove plugin and package versions
asdf plugin-update <name> Update plugin
asdf plugin-update --all Update all plugins

View File

@ -16,17 +16,17 @@ plugin_current_command() {
check_for_deprecated_plugin "$plugin_name"
if [ -z "$version" ]; then
echo "No version set for $plugin_name"
printf "%s\\n" "No version set for $plugin_name"
exit 1
else
echo "$version (set by $version_file_path)"
printf "%-8s%s\\n" "$version" "(set by $version_file_path)"
fi
}
current_command() {
if [ $# -eq 0 ]; then
for plugin in $(plugin_list_command); do
echo "$plugin $(plugin_current_command "$plugin")"
printf "%-15s%s\\n" "$plugin" "$(plugin_current_command "$plugin")"
done
else
local plugin=$1

View File

@ -1,9 +1,26 @@
plugin_list_all_command() {
initialize_or_update_repository
local plugins_path
plugins_path="$(asdf_dir)/repository/plugins"
for plugin in $plugins_path/*; do
basename "$plugin"
done
local plugins_index_path
plugins_index_path="$(asdf_dir)/repository/plugins"
local plugins_local_path
plugins_local_path="$(get_plugin_path)"
if ls "$plugins_index_path" &> /dev/null; then
for index_plugin in $plugins_index_path/*; do
index_plugin_name=$(basename "$index_plugin")
source_url=$(get_plugin_source_url "$index_plugin_name")
installed_flag=""
for local_plugin in $plugins_local_path/*; do
local_plugin_name=$(basename "$local_plugin")
[[ "$index_plugin_name" == "$local_plugin_name" ]] && installed_flag="*"
done
printf "%-15s %-1s%s\\n" "$index_plugin_name" "$installed_flag" "$source_url"
done
else
printf "%s%s\\n" "error: index of plugins not found at " "$plugins_index_path"
fi
}

View File

@ -1,12 +1,32 @@
plugin_list_command() {
local plugins_path
plugins_path=$(get_plugin_path)
local flag=$1
if ls "$plugins_path" &> /dev/null; then
for plugin_path in $plugins_path/* ; do
basename "$plugin_path"
done
# 0 || 1 with flag
if [ $# -eq 0 ] || ([ $# -eq 1 ] && [ "$flag" == "--urls" ]); then
# valid command
local plugins_path
plugins_path=$(get_plugin_path)
if ls "$plugins_path" &> /dev/null; then
for plugin_path in $plugins_path/* ; do
plugin_name=$(basename "$plugin_path")
if [ $# -eq 0 ]; then
printf "%s\\n" "$plugin_name"
else
source_url=$(get_plugin_source_url "$plugin_name")
printf "%-15s %s\\n" "$plugin_name" "$source_url"
fi
done
else
printf "%s\\n" 'Oohes nooes ~! No plugins installed'
fi
else
echo 'Oohes nooes ~! No plugins installed'
display_error "usage: asdf plugin-list [--urls]"
exit 1
fi
}

View File

@ -25,7 +25,7 @@ teardown() {
run current_command "dummy"
[ "$status" -eq 0 ]
[ "$output" = "1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
[ "$output" = "1.1.0 (set by $PROJECT_DIR/.tool-versions)" ]
}
@test "current should derive from the legacy file if enabled" {
@ -35,7 +35,7 @@ teardown() {
run current_command "dummy"
[ "$status" -eq 0 ]
[ "$output" = "1.2.0 (set by $PROJECT_DIR/.dummy-version)" ]
[ "$output" = "1.2.0 (set by $PROJECT_DIR/.dummy-version)" ]
}
@test "current should error when the plugin doesn't exist" {
@ -75,9 +75,9 @@ teardown() {
echo 'foobar 1.0.0' >> $PROJECT_DIR/.tool-versions
run current_command
expected="baz No version set for baz
dummy 1.1.0 (set by $PROJECT_DIR/.tool-versions)
foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)"
expected="baz No version set for baz
dummy 1.1.0 (set by $PROJECT_DIR/.tool-versions)
foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)"
[ "$expected" = "$output" ]
}

View File

@ -18,6 +18,7 @@ teardown() {
[ "$status" -eq 0 ]
run plugin_list_command
# whitespace between 'elixir' and url is from printf %-15s %s format
[ "$output" = "elixir" ]
}