From 56cdfcaa9038669674d5d88e9fea2745b2f73641 Mon Sep 17 00:00:00 2001 From: Eric Peters Date: Mon, 23 Sep 2019 10:23:48 -0700 Subject: [PATCH] Add --numeric-version, --script-version, and update --version to print both versions --- .../src/test/scala/RunnerTest.scala | 28 +++++++++++++++++-- src/linux/usr/share/man/man1/sbt.1 | 6 +++- src/universal/bin/sbt | 16 +++++++++-- 3 files changed, 43 insertions(+), 7 deletions(-) mode change 100644 => 100755 integration-test/src/test/scala/RunnerTest.scala diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala old mode 100644 new mode 100755 index c5c1d4c80..6b94a7e3e --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -82,14 +82,36 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } - test("sbt -V|-version should print sbtVersion") { + // 1.3.0, 1.3.0-M4 + private val versionRegEx = "\\d(\\.\\d+){2}(-\\w+)?" + + test("sbt -V|-version|--version should print sbtVersion") { val out = sbtProcessWithOpts("-version", "", "").!!.trim - val expectedVersion = "^sbt version in this project: \\d\\.\\d+\\.\\d+\\S*$" + val expectedVersion = + s"""|(?m)^sbt version in this project: $versionRegEx + |sbt script version: $versionRegEx$$ + |""".stripMargin.trim.replace("\n", "\\n") assert(out.matches(expectedVersion)) - val out2 = sbtProcessWithOpts("-V", "", "").!!.trim + val out2 = sbtProcessWithOpts("--version", "", "").!!.trim assert(out2.matches(expectedVersion)) + + val out3 = sbtProcessWithOpts("-V", "", "").!!.trim + assert(out3.matches(expectedVersion)) () } + test("sbt --numeric-version should print sbt script version") { + val out = sbtProcessWithOpts("--numeric-version", "", "").!!.trim + val expectedVersion = "^"+versionRegEx+"$" + assert(out.matches(expectedVersion)) + () + } + + test("sbt --script-version should print sbtVersion") { + val out = sbtProcessWithOpts("--numeric-version", "", "").!!.trim + val expectedVersion = "^"+versionRegEx+"$" + assert(out.matches(expectedVersion)) + () + } } diff --git a/src/linux/usr/share/man/man1/sbt.1 b/src/linux/usr/share/man/man1/sbt.1 index 62c10bf29..523b3fe56 100644 --- a/src/linux/usr/share/man/man1/sbt.1 +++ b/src/linux/usr/share/man/man1/sbt.1 @@ -17,7 +17,11 @@ Show help options. .IP "-v, --verbose" turn up the noise .IP "-V, --version" -print the version of mothership sbt +print sbt version information +.IP "--numeric-version" +print the numeric sbt version (sbt sbtVersion) +.IP "--script-version" +print the version of sbt script .IP "-d, --debug" set sbt log level to debug .IP --no-colors diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index 4907c64c7..dd50aeea6 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -6,7 +6,9 @@ declare -a java_args declare -a scalac_args declare -a sbt_commands declare -a sbt_options +declare -a print_version declare -a print_sbt_version +declare -a print_sbt_script_version declare java_cmd=java declare java_version declare init_sbt_version=_to_be_replaced @@ -361,8 +363,12 @@ run() { fi if [[ $print_sbt_version ]]; then - # print sbtVersion + execRunner "$java_cmd" -jar "$sbt_jar" "sbtVersion" | tail -1 | sed -e 's/\[info\]//g' + elif [[ $print_sbt_script_version ]]; then + echo "$init_sbt_version" + elif [[ $print_version ]]; then execRunner "$java_cmd" -jar "$sbt_jar" "sbtVersion" | tail -1 | sed -e 's/\[info\]/sbt version in this project:/g' + echo "sbt script version: $init_sbt_version" else # run sbt execRunner "$java_cmd" \ @@ -396,7 +402,9 @@ Usage: `basename "$0"` [options] -h | --help print this message -v | --verbose this runner is chattier - -V | --version print the version of mothership sbt + -V | --version print sbt version information + --numeric-version print the numeric sbt version (sbt sbtVersion) + --script-version print the version of sbt script -d | --debug set sbt log level to debug --no-colors disable ANSI color codes --color=auto|always|true|false|never @@ -504,7 +512,9 @@ process_args () { case "$1" in -h|-help|--help) usage; exit 1 ;; -v|-verbose|--verbose) sbt_verbose=1 && shift ;; - -V|-version|--version) print_sbt_version=1 && shift ;; + -V|-version|--version) print_version=1 && shift ;; + --numeric-version) print_sbt_version=1 && shift ;; + --script-version) print_sbt_script_version=1 && shift ;; -d|-debug|--debug) sbt_debug=1 && addSbt "-debug" && shift ;; -ivy|--ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;;