From d294c9cdf027455e9eb4acf6fd2053cf35c26518 Mon Sep 17 00:00:00 2001 From: Marco Vermeulen Date: Tue, 9 Oct 2012 13:18:24 +0100 Subject: [PATCH] Issue #4 and #12: Check for presence of candidate and version. Also bolstered list and use commands. --- .../cucumber/gvm/command_line_interop.feature | 5 ++--- .../cucumber/gvm/uninstall_candidate.feature | 12 ++++++++++++ src/test/groovy/gvm/VertxUtils.groovy | 4 ++-- srv/scripts/gvm | 17 ++++++++++++----- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/test/cucumber/gvm/command_line_interop.feature b/src/test/cucumber/gvm/command_line_interop.feature index 2f67d2e3..bbd60ba8 100644 --- a/src/test/cucumber/gvm/command_line_interop.feature +++ b/src/test/cucumber/gvm/command_line_interop.feature @@ -18,9 +18,8 @@ Feature: Command Line Interop Scenario: Enter an invalid Candidate When I enter "gvm install groffle" - Then I see "Invalid candidate: groffle" - And I see "Usage: gvm [version]" + Then I see "Stop! groffle is not a valid candidate." Scenario: Use without providing a Candidate When I enter "gvm use" - Then I see "Usage: gvm [version]" \ No newline at end of file + Then I see "Usage: gvm [version]" diff --git a/src/test/cucumber/gvm/uninstall_candidate.feature b/src/test/cucumber/gvm/uninstall_candidate.feature index 6adb760f..0795ca50 100644 --- a/src/test/cucumber/gvm/uninstall_candidate.feature +++ b/src/test/cucumber/gvm/uninstall_candidate.feature @@ -19,4 +19,16 @@ Feature: Uninstall Candidate When I enter "gvm uninstall grails 1.3.9" Then I see "grails 1.3.9 is not installed." And the candidate "grails" version "1.3.9" is not installed + + Scenario: Attempt uninstalling with no Candidate specified + When I enter "gvm uninstall" + Then I see "No candidate provided." + + Scenario: Attempt uninstalling with an invalid Candidate specified + When I enter "gvm uninstall groffle" + Then I see "Stop! groffle is not a valid candidate." + + Scenario: Attempt uninstalling without a version provided + When I enter "gvm uninstall grails" + Then I see "No candidate version provided." diff --git a/src/test/groovy/gvm/VertxUtils.groovy b/src/test/groovy/gvm/VertxUtils.groovy index 3c06ea74..8d650808 100644 --- a/src/test/groovy/gvm/VertxUtils.groovy +++ b/src/test/groovy/gvm/VertxUtils.groovy @@ -10,7 +10,7 @@ class VertxUtils { final static candidates = [grails:grails] final static defaults = [grails:'2.1.0'] - static final gvmVersion = '0.1' + static final gvmVersion = '0.3' static final serverVersion = '0.1' static final vertxVersion = '1.2.3.final' @@ -93,7 +93,7 @@ class VertxUtils { binding = [server:serverVersion, vertx:vertxVersion] } else { gtplFile = new File('srv/templates/upgrade.gtpl') - binding = [version:gvmVersion] + binding = [version:version, gvmVersion:gvmVersion] } def template = templateEngine.createTemplate(gtplFile).make(binding) req.response.end template.toString() diff --git a/srv/scripts/gvm b/srv/scripts/gvm index de952af5..39d5b4e9 100755 --- a/srv/scripts/gvm +++ b/srv/scripts/gvm @@ -26,6 +26,14 @@ function check_candidate_present { fi } +function check_version_present { + if [ -z "$1" ]; then + echo -e "\nNo candidate version provided." + help + exit 0 + fi +} + function determine_candidate_version { if [ -z "$1" ]; then VERSION=$(curl -s "$GVM_SERVICE/candidates/$CANDIDATE/default") @@ -168,11 +176,7 @@ function gvm-install { function gvm-use { CANDIDATE="$1" - - if [ -z "$2" ]; then - help - exit 0 - fi + check_candidate_present "$CANDIDATE" determine_candidate_version "$2" check_not_installed @@ -187,6 +191,7 @@ function gvm-use { function gvm-list { CANDIDATE="$1" + check_candidate_present "$CANDIDATE" build_version_csv "$CANDIDATE" determine_current_version "$CANDIDATE" FRAGMENT=$(curl -s "$GVM_SERVICE/candidates/$CANDIDATE/list?current=$CURRENT&installed=$CSV") @@ -196,6 +201,8 @@ function gvm-list { function gvm-uninstall { CANDIDATE="$1" VERSION="$2" + check_candidate_present "$CANDIDATE" + check_version_present "$VERSION" CURRENT=$(readlink "$GVM_DIR/$CANDIDATE/current" | sed -e "s_$GVM_DIR/$CANDIDATE/__g") if [ -h "$GVM_DIR/$CANDIDATE/current" -a "$VERSION" == "$CURRENT" ]; then echo ""