Merge pull request #288 from er1c/versions

Add --numeric-version, --script-version, and update --version to print both versions
This commit is contained in:
eugene yokota 2019-09-24 21:03:35 -04:00 committed by GitHub
commit 9fc62e5ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 7 deletions

28
integration-test/src/test/scala/RunnerTest.scala Normal file → Executable file
View File

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

View File

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

View File

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