diff --git a/README.md b/README.md index f40e4582..e580bb29 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,15 @@ asdf plugin-add ```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 diff --git a/help.txt b/help.txt index fb15e7fb..d8d07339 100644 --- a/help.txt +++ b/help.txt @@ -2,7 +2,8 @@ MANAGE PLUGINS asdf plugin-add [] 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 Remove plugin and package versions asdf plugin-update Update plugin asdf plugin-update --all Update all plugins diff --git a/lib/commands/current.sh b/lib/commands/current.sh index 7cf26c95..d397d2bf 100644 --- a/lib/commands/current.sh +++ b/lib/commands/current.sh @@ -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 diff --git a/lib/commands/plugin-list-all.sh b/lib/commands/plugin-list-all.sh index 789c2235..ee7bc244 100644 --- a/lib/commands/plugin-list-all.sh +++ b/lib/commands/plugin-list-all.sh @@ -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 } diff --git a/lib/commands/plugin-list.sh b/lib/commands/plugin-list.sh index 70705b91..cc277ca0 100644 --- a/lib/commands/plugin-list.sh +++ b/lib/commands/plugin-list.sh @@ -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 + } diff --git a/test/current_command.bats b/test/current_command.bats index fd77093a..676410fb 100644 --- a/test/current_command.bats +++ b/test/current_command.bats @@ -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" ] } diff --git a/test/plugin_commands.bats b/test/plugin_commands.bats index 65102387..4d7e4b0c 100644 --- a/test/plugin_commands.bats +++ b/test/plugin_commands.bats @@ -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" ] }