From 56f09ef1eca330b84f884788b182e7a32dafa12e Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 5 Apr 2019 10:20:52 -0400 Subject: [PATCH 1/2] support GNU style double dash options --- .../src/test/scala/RunnerTest.scala | 6 ++ src/universal/bin/sbt | 84 +++++++++---------- src/universal/bin/sbt-launch-lib.bash | 36 ++++---- src/universal/bin/sbt.bat | 6 +- 4 files changed, 70 insertions(+), 62 deletions(-) diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index ab238243c..0b9d63787 100644 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -28,6 +28,12 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } + test("sbt --no-colors") { + val out = sbtProcess("compile --no-colors -v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.log.noformat=true")) + () + } + test("sbt -mem 503") { val out = sbtProcess("compile -mem 503 -v").!!.linesIterator.toList assert(out.contains[String]("-Xmx503m")) diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index 3c60188b0..c426ff9ea 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -35,7 +35,7 @@ CYGWIN_FLAG=$(if is_cygwin; then echo true; else echo false; fi) # windows style paths. cygwinpath() { local file="$1" - if [[ "$CYGWIN_FLAG" == "true" ]]; then + if [[ "$CYGWIN_FLAG" == "true" ]]; then #" echo $(cygpath -w $file) else echo $file @@ -387,7 +387,7 @@ run() { copyRt #If we're in cygwin, we should use the windows config, and terminal hacks - if [[ "$CYGWIN_FLAG" == "true" ]]; then + if [[ "$CYGWIN_FLAG" == "true" ]]; then #" stty -icanon min 1 -echo > /dev/null 2>&1 addJava "-Djline.terminal=jline.UnixTerminal" addJava "-Dsbt.cygwin=true" @@ -405,7 +405,7 @@ run() { exit_code=$? # Clean up the terminal from cygwin hacks. - if [[ "$CYGWIN_FLAG" == "true" ]]; then + if [[ "$CYGWIN_FLAG" == "true" ]]; then #" stty icanon echo > /dev/null 2>&1 fi exit $exit_code @@ -421,41 +421,41 @@ usage() { cat < path to global settings/plugins directory (default: ~/.sbt) - -sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) - -ivy path to local Ivy repository (default: ~/.ivy2) - -mem set memory options (default: $sbt_default_mem, which is $(get_mem_opts)) - -no-share use all local caches; no sharing - -no-global uses global caches, but does not use global ~/.sbt directory. - -jvm-debug Turn on JVM debugging, open at the given port. - -batch Disable interactive mode + -h | --help print this message + -v | --verbose this runner is chattier + -d | --debug set sbt log level to debug + --no-colors disable ANSI color codes + --sbt-create start sbt even if current directory contains no sbt project + --sbt-dir path to global settings/plugins directory (default: ~/.sbt) + --sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) + --ivy path to local Ivy repository (default: ~/.ivy2) + --mem set memory options (default: $sbt_default_mem, which is $(get_mem_opts)) + --no-share use all local caches; no sharing + --no-global uses global caches, but does not use global ~/.sbt directory. + --jvm-debug Turn on JVM debugging, open at the given port. + --batch Disable interactive mode # sbt version (default: from project/build.properties if present, else latest release) - -sbt-version use the specified version of sbt - -sbt-jar use the specified jar as the sbt launcher - -sbt-rc use an RC version of sbt - -sbt-snapshot use a snapshot version of sbt + --sbt-version use the specified version of sbt + --sbt-jar use the specified jar as the sbt launcher + --sbt-rc use an RC version of sbt + --sbt-snapshot use a snapshot version of sbt # java version (default: java from PATH, currently $(java -version 2>&1 | grep version)) - -java-home alternate JAVA_HOME + --java-home alternate JAVA_HOME # jvm options and output control - JAVA_OPTS environment variable, if unset uses "$default_java_opts" - .jvmopts if this file exists in the current directory, its contents - are appended to JAVA_OPTS - SBT_OPTS environment variable, if unset uses "$default_sbt_opts" - .sbtopts if this file exists in the current directory, its contents - are prepended to the runner args - /etc/sbt/sbtopts if this file exists, it is prepended to the runner args - -Dkey=val pass -Dkey=val directly to the java runtime - -J-X pass option -X directly to the java runtime - (-J is stripped) - -S-X add -X to sbt's scalacOptions (-S is stripped) + JAVA_OPTS environment variable, if unset uses "$default_java_opts" + .jvmopts if this file exists in the current directory, its contents + are appended to JAVA_OPTS + SBT_OPTS environment variable, if unset uses "$default_sbt_opts" + .sbtopts if this file exists in the current directory, its contents + are prepended to the runner args + /etc/sbt/sbtopts if this file exists, it is prepended to the runner args + -Dkey=val pass -Dkey=val directly to the java runtime + -J-X pass option -X directly to the java runtime + (-J is stripped) + -S-X add -X to sbt's scalacOptions (-S is stripped) In the case of duplicated or conflicting options, the order above shows precedence: JAVA_OPTS lowest, command line options highest. @@ -467,19 +467,19 @@ EOM process_my_args () { while [[ $# -gt 0 ]]; do case "$1" in - -no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; - -no-share) addJava "$noshare_opts" && shift ;; - -no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;; - -sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;; - -sbt-dir) require_arg path "$1" "$2" && addJava "-Dsbt.global.base=$2" && shift 2 ;; - -debug-inc) addJava "-Dxsbt.inc.debug=true" && shift ;; - -batch) exec - -sbt-create) sbt_create=true && shift ;; + -sbt-create|--sbt-create) sbt_create=true && shift ;; - new) sbt_new=true && addResidual "$1" && shift ;; + new) sbt_new=true && addResidual "$1" && shift ;; - *) addResidual "$1" && shift ;; + *) addResidual "$1" && shift ;; esac done diff --git a/src/universal/bin/sbt-launch-lib.bash b/src/universal/bin/sbt-launch-lib.bash index ce022f7db..29631a599 100755 --- a/src/universal/bin/sbt-launch-lib.bash +++ b/src/universal/bin/sbt-launch-lib.bash @@ -175,27 +175,27 @@ jdk_version() { process_args () { while [[ $# -gt 0 ]]; do case "$1" in - -h|-help) usage; exit 1 ;; - -v|-verbose) verbose=1 && shift ;; - -d|-debug) debug=1 && addSbt "-debug" && shift ;; + -h|-help|--help) usage; exit 1 ;; + -v|-verbose|--verbose) verbose=1 && shift ;; + -d|-debug|--debug) debug=1 && addSbt "-debug" && shift ;; - -ivy) require_arg path "$1" "$2" && addJava "-Dsbt.ivy.home=$2" && shift 2 ;; - -mem) require_arg integer "$1" "$2" && sbt_mem="$2" && shift 2 ;; - -jvm-debug) require_arg port "$1" "$2" && addDebugger $2 && shift 2 ;; - -batch) exec nul >nul ) else if "!JVM_DEBUG!" == "true" ( set /a JVM_DEBUG_PORT=%1 2>nul >nul From a47004e01e7409f73c45ebd18bcc09f52fddd63b Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 5 Apr 2019 11:30:59 -0400 Subject: [PATCH 2/2] add options for timings, traces, supershell, and color `--supershell=*` will pass on to `-Dsbt.supershell=*`. --- .../src/test/scala/RunnerTest.scala | 18 ++++++++++++++++++ src/universal/bin/sbt | 14 +++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/integration-test/src/test/scala/RunnerTest.scala b/integration-test/src/test/scala/RunnerTest.scala index 0b9d63787..074d75c04 100644 --- a/integration-test/src/test/scala/RunnerTest.scala +++ b/integration-test/src/test/scala/RunnerTest.scala @@ -34,6 +34,24 @@ object SbtRunnerTest extends SimpleTestSuite with PowerAssertions { () } + test("sbt --color=false") { + val out = sbtProcess("compile --color=false -v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.color=false")) + () + } + + test("sbt --supershell=never") { + val out = sbtProcess("compile --supershell=never -v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.supershell=never")) + () + } + + test("sbt --timings") { + val out = sbtProcess("compile --timings -v").!!.linesIterator.toList + assert(out.contains[String]("-Dsbt.task.timings=true")) + () + } + test("sbt -mem 503") { val out = sbtProcess("compile -mem 503 -v").!!.linesIterator.toList assert(out.contains[String]("-Xmx503m")) diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index c426ff9ea..688b6b6e4 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -425,6 +425,12 @@ Usage: `basename "$0"` [options] -v | --verbose this runner is chattier -d | --debug set sbt log level to debug --no-colors disable ANSI color codes + --color=auto|always|true|false|never + enable or disable ANSI color codes (sbt 1.3 and above) + --supershell=auto|always|true|false|never + enable or disable supershell (sbt 1.3 and above) + --traces generate Trace Event report on shutdown (sbt 1.3 and above) + --timings display task timings report on shutdown --sbt-create start sbt even if current directory contains no sbt project --sbt-dir path to global settings/plugins directory (default: ~/.sbt) --sbt-boot path to shared boot directory (default: ~/.sbt/boot in 0.11 series) @@ -433,7 +439,7 @@ Usage: `basename "$0"` [options] --no-share use all local caches; no sharing --no-global uses global caches, but does not use global ~/.sbt directory. --jvm-debug Turn on JVM debugging, open at the given port. - --batch Disable interactive mode + --batch disable interactive mode # sbt version (default: from project/build.properties if present, else latest release) --sbt-version use the specified version of sbt @@ -468,6 +474,12 @@ process_my_args () { while [[ $# -gt 0 ]]; do case "$1" in -no-colors|--no-colors) addJava "-Dsbt.log.noformat=true" && shift ;; + -timings|--timings) addJava "-Dsbt.task.timings=true" && addJava "-Dsbt.task.timings.on.shutdown=true" && shift ;; + -traces|--traces) addJava "-Dsbt.traces=true" && shift ;; + --supershell=*) addJava "-Dsbt.supershell=${1:13}" && shift ;; + -supershell=*) addJava "-Dsbt.supershell=${1:12}" && shift ;; + --color=*) addJava "-Dsbt.color=${1:8}" && shift ;; + -color=*) addJava "-Dsbt.color=${1:7}" && shift ;; -no-share|--no-share) addJava "$noshare_opts" && shift ;; -no-global|--no-global) addJava "-Dsbt.global.base=$(pwd)/project/.sbtboot" && shift ;; -sbt-boot|--sbt-boot) require_arg path "$1" "$2" && addJava "-Dsbt.boot.directory=$2" && shift 2 ;;