From 94b27fcefad6db1f81f9e4c89acb3562ef560ae8 Mon Sep 17 00:00:00 2001 From: Deokhwan Kim Date: Sat, 17 Feb 2018 09:38:52 -0500 Subject: [PATCH] Confirm a user's intent if the current dir doesn't look like an sbt dir Fixes #212 --- src/universal/bin/sbt | 19 +++++++++++++++++++ src/universal/bin/sbt.bat | 28 ++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/universal/bin/sbt b/src/universal/bin/sbt index 9070dab7c..2be3f7c69 100755 --- a/src/universal/bin/sbt +++ b/src/universal/bin/sbt @@ -127,12 +127,31 @@ process_my_args () { -sbt-create) sbt_create=true && shift ;; + new) sbt_new=true && addResidual "$1" && shift ;; + *) addResidual "$1" && shift ;; esac done # Now, ensure sbt version is used. [[ "${sbt_version}XXX" != "XXX" ]] && addJava "-Dsbt.version=$sbt_version" + + # Confirm a user's intent if the current directory does not look like an sbt + # top-level directory and neither the -sbt-create option nor the "new" + # command was given. + [[ -f ./build.sbt || -d ./project || -n "$sbt_create" || -n "$sbt_new" ]] || { + echo "[warn] Neither build.sbt nor a 'project' directory in the current directory: $(pwd)" + while true; do + echo 'c) continue' + echo 'q) quit' + + read -p '? ' || exit 1 + case "$REPLY" in + c|C) break ;; + q|Q) exit 1 ;; + esac + done + } } loadConfigFile() { diff --git a/src/universal/bin/sbt.bat b/src/universal/bin/sbt.bat index 237accc05..2569b4e6c 100644 --- a/src/universal/bin/sbt.bat +++ b/src/universal/bin/sbt.bat @@ -68,6 +68,9 @@ if "%~1" == "-jvm-debug" ( if not "%~1" == "!JVM_DEBUG_PORT!" ( set SBT_ARGS=!SBT_ARGS! %1 ) +) else if /I "%~1" == "new" ( + set sbt_new=true + set SBT_ARGS=!SBT_ARGS! %1 ) else ( set SBT_ARGS=!SBT_ARGS! %1 ) @@ -76,6 +79,31 @@ shift goto args_loop :args_end +rem Confirm a user's intent if the current directory does not look like an sbt +rem top-level directory and the "new" command was not given. +if not exist build.sbt ( + if not exist project\ ( + if not defined sbt_new ( + echo [warn] Neither build.sbt nor a 'project' directory in the current directory: %CD% + setlocal +:confirm + echo c^) continue + echo q^) quit + + set /P reply=?^ + if /I "!reply!" == "c" ( + goto confirm_end + ) else if /I "!reply!" == "q" ( + exit /B 1 + ) + + goto confirm +:confirm_end + endlocal + ) + ) +) + if defined JVM_DEBUG_PORT ( set _JAVA_OPTS=!_JAVA_OPTS! -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=!JVM_DEBUG_PORT! )