From eb5e5b780c134bb7c9ea7c80ba67195aee014ca0 Mon Sep 17 00:00:00 2001 From: AJ Foster Date: Sun, 25 Feb 2018 17:42:33 -0500 Subject: [PATCH] Refactor "no version set" message to utilities --- bin/private/asdf-exec | 2 +- lib/commands/current.sh | 2 +- lib/commands/which.sh | 2 +- lib/utils.sh | 5 +++++ test/current_command.bats | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/private/asdf-exec b/bin/private/asdf-exec index eec5096d..7d3b2318 100755 --- a/bin/private/asdf-exec +++ b/bin/private/asdf-exec @@ -12,7 +12,7 @@ check_if_plugin_exists "$plugin_name" full_version=$(get_preset_version_for "$plugin_name") if [ "$full_version" == "" ]; then - echo "No version set for ${plugin_name}: please run \`asdf ${plugin_name} \`" + display_no_version_set "$plugin_name" exit -1 fi diff --git a/lib/commands/current.sh b/lib/commands/current.sh index 559063a6..7ae949fc 100644 --- a/lib/commands/current.sh +++ b/lib/commands/current.sh @@ -16,7 +16,7 @@ plugin_current_command() { check_for_deprecated_plugin "$plugin_name" if [ -z "$version" ]; then - printf "%s\\n" "No version set for $plugin_name: please run \`asdf ${plugin_name} \`" + printf "%s\\n" "$(display_no_version_set "$plugin_name")" exit 1 else printf "%-8s%s\\n" "$version" "(set by $version_file_path)" diff --git a/lib/commands/which.sh b/lib/commands/which.sh index 10033d39..715a4c3e 100644 --- a/lib/commands/which.sh +++ b/lib/commands/which.sh @@ -14,7 +14,7 @@ current_version() { check_for_deprecated_plugin "$plugin_name" if [ -z "$version" ]; then - echo "No version set for $plugin_name: please run \`asdf ${plugin_name} \`" + display_no_version_set "$plugin_name" exit 1 else echo "$version" diff --git a/lib/utils.sh b/lib/utils.sh index f0430d24..e6ea2279 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -160,6 +160,11 @@ find_version() { fi } +display_no_version_set() { + local plugin_name=$1 + echo "No version set for ${plugin_name}; please run \`asdf ${plugin_name} \`" +} + get_version_from_env () { local plugin_name=$1 local upcase_name diff --git a/test/current_command.bats b/test/current_command.bats index a730b377..70d8ecaa 100644 --- a/test/current_command.bats +++ b/test/current_command.bats @@ -75,7 +75,7 @@ teardown() { echo 'foobar 1.0.0' >> $PROJECT_DIR/.tool-versions run current_command - expected="baz No version set for baz: please run \`asdf baz \` + expected="baz No version set for baz; please run \`asdf baz \` dummy 1.1.0 (set by $PROJECT_DIR/.tool-versions) foobar 1.0.0 (set by $PROJECT_DIR/.tool-versions)"