From 2c2bfdebc8446b01f8aea5643d22e5824f8282d6 Mon Sep 17 00:00:00 2001 From: Yasuharu Nakano Date: Sun, 8 Mar 2015 22:49:40 +0900 Subject: [PATCH] Add 'outdated' command. --- src/main/bash/gvm-outdated.sh | 55 +++++++++++++++++++ .../cucumber/gvm/outdated_candidate.feature | 43 +++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/main/bash/gvm-outdated.sh create mode 100644 src/test/cucumber/gvm/outdated_candidate.feature diff --git a/src/main/bash/gvm-outdated.sh b/src/main/bash/gvm-outdated.sh new file mode 100644 index 00000000..cb75b0a9 --- /dev/null +++ b/src/main/bash/gvm-outdated.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +function __gvmtool_determine_outdated_version { + local candidate local_versions remote_default_version + candidate="$1" + + # Resolve local versions + local_versions="$(echo $(find "${GVM_DIR}/${candidate}" -maxdepth 1 -mindepth 1 -type d -exec basename '{}' \;) | sed -e "s/ /, /g" )" + if [ ${#local_versions} -eq 0 ]; then + return 1 + fi + + # Resolve remote default version + remote_default_version="$(curl -s "${GVM_SERVICE}/candidates/${candidate}/default")" + if [ -z "$remote_default_version" ]; then + return 2 + fi + + # Check outdated or not + if [ ! -d "${GVM_DIR}/${candidate}/${remote_default_version}" ]; then + echo "${candidate} (${local_versions} < ${remote_default_version})" + fi +} + +function __gvmtool_outdated { + local all candidates candidate outdated installed_count + if [ -n "$1" ]; then + all=false + candidates=$1 + else + all=true + candidates=${GVM_CANDIDATES[@]} + fi + installed_count=0 + for candidate in ${candidates}; do + outdated="$(__gvmtool_determine_outdated_version "${candidate}")" + case $? in + 1) + $all || echo "Not using any version of ${candidate}" + ;; + 2) + echo "" + echo "Stop! Could not get remote version of ${candidate}" + return 1 + ;; + *) + [ -n "${outdated}" ] && echo "${outdated}" + (( installed_count += 1 )) + ;; + esac + done + if $all && [ ${installed_count} -eq 0 ]; then + echo 'No candidates are in use' + fi +} diff --git a/src/test/cucumber/gvm/outdated_candidate.feature b/src/test/cucumber/gvm/outdated_candidate.feature new file mode 100644 index 00000000..8fa8a5fa --- /dev/null +++ b/src/test/cucumber/gvm/outdated_candidate.feature @@ -0,0 +1,43 @@ +Feature: Outdated Candidate + + Background: + Given the internet is reachable + And an initialised environment + + Scenario: Display outdated candidate version in use when it is outdated + Given the candidate "grails" version "1.3.9" is already installed and default + And the default "grails" candidate is "2.4.4" + When I enter "gvm outdated grails" + Then I see "grails (1.3.9 < 2.4.4)" + + Scenario: Display outdated candidate version in use when it is not outdated + Given the candidate "grails" version "1.3.9" is already installed and default + And the default "grails" candidate is "1.3.9" + When I enter "gvm outdated grails" + Then I do not see "grails" + + Scenario: Display outdated candidate version when none is in use + Given the candidate "grails" does not exist + When I enter "gvm outdated grails" + Then I see "Not using any version of grails" + + Scenario: Display outdated candidate versions when none is specified and none is in use + Given the candidate "grails" does not exist + When I enter "gvm outdated" + Then I see "No candidates are in use" + + Scenario: Display outdated candidate versions when none is specified and one is in use + Given the candidate "grails" version "1.3.9" is already installed and default + And the default "grails" candidate is "2.4.4" + When I enter "gvm outdated" + Then I see "grails (1.3.9 < 2.4.4)" + + Scenario: Display outdated candidate versions when none is specified and multiple are in use + Given the candidate "grails" version "1.3.9" is already installed and default + And the default "grails" candidate is "2.4.4" + And the candidate "groovy" version "2.0.5" is already installed and default + And the default "groovy" candidate is "2.4.1" + When I enter "gvm outdated" + Then I see "grails (1.3.9 < 2.4.4)" + And I see "groovy (2.0.5 < 2.4.1)" +