add --urls flag for asdf list-plugins

Fixed tests due to use of printf
This commit is contained in:
jthegedus 2018-01-14 19:38:00 +11:00
parent 88d47bbd69
commit f99bdc75c0
6 changed files with 45 additions and 22 deletions

View File

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

View File

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

View File

@ -16,20 +16,17 @@ plugin_current_command() {
check_for_deprecated_plugin "$plugin_name" check_for_deprecated_plugin "$plugin_name"
if [ -z "$version" ]; then if [ -z "$version" ]; then
printf "No version set for $plugin_name" printf "%s\\n" "No version set for $plugin_name"
exit 1 exit 1
else else
printf "%-8s%s" "$version" "(set by" "$version_file_path)" printf "%-8s%s\\n" "$version" "(set by $version_file_path)"
fi fi
} }
current_command() { current_command() {
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
for plugin in $(plugin_list_command); do for plugin in $(plugin_list_command); do
#plugin_list_command returns <name url> pairs, so filter urls printf "%-15s%s\\n" "$plugin" "$(plugin_current_command "$plugin")"
if [[ $plugin != *"http"* ]] ; then
printf "%-15s%s\\n" "$plugin" "$(plugin_current_command "$plugin")"
fi
done done
else else
local plugin=$1 local plugin=$1

View File

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

View File

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

View File

@ -19,7 +19,7 @@ teardown() {
run plugin_list_command run plugin_list_command
# whitespace between 'elixir' and url is from printf %-15s %s format # whitespace between 'elixir' and url is from printf %-15s %s format
[ "$output" = "elixir https://github.com/asdf-vm/asdf-elixir" ] [ "$output" = "elixir" ]
} }
@test "plugin_add command with no URL specified fails if the plugin doesn't exist" { @test "plugin_add command with no URL specified fails if the plugin doesn't exist" {