From 56f09ef1eca330b84f884788b182e7a32dafa12e Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 5 Apr 2019 10:20:52 -0400 Subject: [PATCH] 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