Add 'outdated' command.

This commit is contained in:
Yasuharu Nakano
2015-03-08 22:49:40 +09:00
parent cf49338e4d
commit 2c2bfdebc8
2 changed files with 98 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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)"