diff --git a/src/main/resources/scripts/gvm-install.sh b/src/main/resources/scripts/gvm-install.sh index c2cc3ccc..230c2bb2 100644 --- a/src/main/resources/scripts/gvm-install.sh +++ b/src/main/resources/scripts/gvm-install.sh @@ -31,8 +31,10 @@ function __gvmtool_install { if [[ ${VERSION_VALID} == 'valid' ]]; then __gvmtool_install_candidate_version "${CANDIDATE}" "${VERSION}" || return 1 - echo -n "Do you want ${CANDIDATE} ${VERSION} to be set as default? (Y/n): " - read USE + if [[ -z "${gvm_auto_answer}" ]]; then + echo -n "Do you want ${CANDIDATE} ${VERSION} to be set as default? (Y/n): " + read USE + fi if [[ -z "${USE}" || "${USE}" == "y" || "${USE}" == "Y" ]]; then echo "" echo "Setting ${CANDIDATE} ${VERSION} as default." diff --git a/src/main/resources/scripts/gvm-use.sh b/src/main/resources/scripts/gvm-use.sh index 9ec3b403..c5a9978d 100644 --- a/src/main/resources/scripts/gvm-use.sh +++ b/src/main/resources/scripts/gvm-use.sh @@ -24,8 +24,10 @@ function __gvmtool_use { if [[ "${GVM_ONLINE}" == "true" && ! -d "${GVM_DIR}/${CANDIDATE}/${VERSION}" ]]; then echo "" echo "Stop! ${CANDIDATE} ${VERSION} is not installed." - echo -n "Do you want to install it now? (Y/n): " - read INSTALL + if [[ -z "${gvm_auto_answer}" ]]; then + echo -n "Do you want to install it now? (Y/n): " + read INSTALL + fi if [[ -z "${INSTALL}" || "${INSTALL}" == "y" || "${INSTALL}" == "Y" ]]; then __gvmtool_install_candidate_version "${CANDIDATE}" "${VERSION}" else diff --git a/src/test/cucumber/gvm/install_candidate.feature b/src/test/cucumber/gvm/install_candidate.feature index 00dea05a..a85b8942 100644 --- a/src/test/cucumber/gvm/install_candidate.feature +++ b/src/test/cucumber/gvm/install_candidate.feature @@ -31,6 +31,14 @@ Feature: Install Candidate And I see "Setting grails 2.1.0 as default." Then the candidate "grails" version "2.1.0" should be the default + Scenario: Install a candidate and select to use it automatically + And I have configured autoinstall="Y" + When I enter "gvm install grails 2.1.0" + Then the candidate "grails" version "2.1.0" is installed + And I see "Done installing!" + And I see "Setting grails 2.1.0 as default." + Then the candidate "grails" version "2.1.0" should be the default + Scenario: Install a candidate and do not select to use it When I enter "gvm install grails 2.1.0" and answer "n" Then the candidate "grails" version "2.1.0" is installed diff --git a/src/test/cucumber/gvm/use_and_default_candidate.feature b/src/test/cucumber/gvm/use_and_default_candidate.feature index 19422298..d07a50f2 100644 --- a/src/test/cucumber/gvm/use_and_default_candidate.feature +++ b/src/test/cucumber/gvm/use_and_default_candidate.feature @@ -20,6 +20,13 @@ Feature: Use and Default Candidate Then I see "Using groovy version 1.8.8 in this shell." And the candidate "groovy" version "1.8.8" should be in use + Scenario: Use a candidate version that is automatically installed + And I have configured autoinstall="Y" + When I enter "gvm use groovy 1.8.8" + Then I see "Stop! groovy 1.8.8 is not installed." + Then I see "Using groovy version 1.8.8 in this shell." + And the candidate "groovy" version "1.8.8" should be in use + Scenario: Use a candidate version that does not exist When I enter "gvm use groovy 1.9.9" Then I see "Stop! 1.9.9 is not a valid groovy version." diff --git a/src/test/resources/gvm/installation_steps.groovy b/src/test/resources/gvm/installation_steps.groovy index 11533ea9..bf18cd91 100644 --- a/src/test/resources/gvm/installation_steps.groovy +++ b/src/test/resources/gvm/installation_steps.groovy @@ -80,6 +80,11 @@ And(~'^the candidate "([^"]*)" version "([^"]*)" is already linked to "([^"]*)"$ Files.createSymbolicLink(link, target) } +And(~'^I have configured autoinstall="([^"]*)"$') { String flag -> + def configFile = new File("$gvmDir/etc/config") + configFile.write "gvm_auto_answer=${flag}" +} + private prepareCandidateFolder(String baseDir, String candidate, String version) { def directory = "$baseDir/$candidate/$version" prepareCandidateBinFolder directory, candidate, version diff --git a/src/test/resources/gvm/use_steps.groovy b/src/test/resources/gvm/use_steps.groovy index f3526d24..471b6b81 100644 --- a/src/test/resources/gvm/use_steps.groovy +++ b/src/test/resources/gvm/use_steps.groovy @@ -42,4 +42,4 @@ Then(~'^the candidate "([^"]*)" version "([^"]*)" should not be the default$') { Then(~'^the candidate "([^"]*)" is no longer selected$') { String candidate -> def symlink = new File("$gvmDir/$candidate/current") assert ! symlink.exists() -} \ No newline at end of file +}