From e93d1430116e87ac811db52c974fb03bd1e83e7e Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 14 Nov 2022 11:18:53 +0100 Subject: [PATCH 1/7] Preseve first-position of some essential mill opitons --- millw | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/millw b/millw index d93110a..1654d7e 100755 --- a/millw +++ b/millw @@ -169,6 +169,13 @@ if [ -z "$MILL_MAIN_CLI" ] ; then MILL_MAIN_CLI="${0}" fi +MILL_FIRST_ARG="" +if [ "$1" = "--bsp" -o "$1" = "-i" -o "$1" = "--interactive" -o "$1" = "--no-server" -o "$1" = "--repl" -o "$1" = "--help" ] ; then + # Need to preserve the first position of those listed options + MILL_FIRST_ARG=$1 + shift +fi + unset MILL_DOWNLOAD_PATH unset MILL_OLD_DOWNLOAD_PATH unset OLD_MILL @@ -176,4 +183,4 @@ unset MILL_VERSION unset MILL_VERSION_TAG unset MILL_REPO_URL -exec "${MILL}" -D "mill.main.cli=${MILL_MAIN_CLI}" "$@" +exec "${MILL}" $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@" From 7eebd8d11e0b1b40b7242b9a3ac4bb1bbb3d6081 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 14 Nov 2022 11:25:40 +0100 Subject: [PATCH 2/7] Replace with more stable (and protable) OR condition --- millw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/millw b/millw index 1654d7e..33a66b2 100755 --- a/millw +++ b/millw @@ -170,7 +170,7 @@ if [ -z "$MILL_MAIN_CLI" ] ; then fi MILL_FIRST_ARG="" -if [ "$1" = "--bsp" -o "$1" = "-i" -o "$1" = "--interactive" -o "$1" = "--no-server" -o "$1" = "--repl" -o "$1" = "--help" ] ; then +if [ "$1" = "--bsp" ] || [ "$1" = "-i" ] || [ "$1" = "--interactive" ] || [ "$1" = "--no-server" ] || [ "$1" = "--repl" ] || [ "$1" = "--help" ] ; then # Need to preserve the first position of those listed options MILL_FIRST_ARG=$1 shift From 5fadbff4e6040731407501eacf63a8666db6e295 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Mon, 14 Nov 2022 11:30:09 +0100 Subject: [PATCH 3/7] Added hint for sheckcheck --- millw | 2 ++ 1 file changed, 2 insertions(+) diff --git a/millw b/millw index 33a66b2..bddfcd4 100755 --- a/millw +++ b/millw @@ -183,4 +183,6 @@ unset MILL_VERSION unset MILL_VERSION_TAG unset MILL_REPO_URL +# We don't quote MILL_FIRST_ARG on purpose, so we can expand the empty value without quotes +# shellcheck disable=SC2086 exec "${MILL}" $MILL_FIRST_ARG -D "mill.main.cli=${MILL_MAIN_CLI}" "$@" From 728adba28a2322c3930f3d548cc17029b6e95172 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 15 Nov 2022 09:42:23 +0100 Subject: [PATCH 4/7] Fist first arg handling for bat script --- millw.bat | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/millw.bat b/millw.bat index 69f6773..47db264 100644 --- a/millw.bat +++ b/millw.bat @@ -108,12 +108,44 @@ set MILL_DOWNLOAD_PATH= set MILL_VERSION= set MILL_REPO_URL= -set MILL_PARAMS=%* - if [!MILL_MAIN_CLI!]==[] ( set "MILL_MAIN_CLI=%0" ) +REM Need to preserve the first position of those listed options +set MILL_FIRST_ARG= +if [%~1%]==[--bsp] ( + set MILL_FIRST_ARG=%1% + shift +) else ( + if [%~1%]==[-i] ( + set MILL_FIRST_ARG=%1% + shift + ) else ( + if [%~1%]==[--interactive] ( + set MILL_FIRST_ARG=%1% + shift + ) else ( + if [%~1%]==[--no-server] ( + set MILL_FIRST_ARG=%1% + shift + ) else ( + if [%~1%]==[--repl] ( + set MILL_FIRST_ARG=%1% + shift + ) else ( + if [%~1%]==[--help] ( + set MILL_FIRST_ARG=%1% + shift + ) + ) + ) + ) + ) +) + +set MILL_PARAMS=%* + if defined STRIP_VERSION_PARAMS ( for /f "tokens=1-2*" %%a in ("%*") do ( rem strip %%a - It's the "--mill-version" option. @@ -123,4 +155,4 @@ if defined STRIP_VERSION_PARAMS ( ) ) -"%MILL%" -D "mill.main.cli=%MILL_MAIN_CLI%" %MILL_PARAMS% +"%MILL%" $MILL_FIRST_ARG% -D "mill.main.cli=%MILL_MAIN_CLI%" %MILL_PARAMS% From 1a6837be59a16fb4719c88130c264e59a7bf4b1c Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 15 Nov 2022 09:53:35 +0100 Subject: [PATCH 5/7] batch script fun --- millw.bat | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/millw.bat b/millw.bat index 47db264..cf8beae 100644 --- a/millw.bat +++ b/millw.bat @@ -120,23 +120,23 @@ if [%~1%]==[--bsp] ( ) else ( if [%~1%]==[-i] ( set MILL_FIRST_ARG=%1% - shift + set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--interactive] ( set MILL_FIRST_ARG=%1% - shift + set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--no-server] ( set MILL_FIRST_ARG=%1% - shift + set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--repl] ( set MILL_FIRST_ARG=%1% - shift + set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--help] ( set MILL_FIRST_ARG=%1% - shift + set "STRIP_FIRST_ARG=true" ) ) ) @@ -146,13 +146,27 @@ if [%~1%]==[--bsp] ( set MILL_PARAMS=%* -if defined STRIP_VERSION_PARAMS ( +if defined STRIP_FIRST_ARG ( + if defined STRIP_VERSION_PARAMS ( + for /f "tokens=1-3*" %%a in ("%*") do ( + set MILL_PARAMS=%%d + ) + ) else ( + for /f "tokens=1*" %%a in ("%*") do ( + rem strip %%a - It's the first arg + rem keep %%c - It's the remaining options. + set MILL_PARAMS=%%b + ) + ) +) else ( + if defined STRIP_VERSION_PARAMS ( for /f "tokens=1-2*" %%a in ("%*") do ( rem strip %%a - It's the "--mill-version" option. rem strip %%b - it's the version number that comes after the option. rem keep %%c - It's the remaining options. set MILL_PARAMS=%%c ) + ) ) "%MILL%" $MILL_FIRST_ARG% -D "mill.main.cli=%MILL_MAIN_CLI%" %MILL_PARAMS% From d9cdea2e041c88ac3ebe1e8aa2f2ff37a7588914 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 15 Nov 2022 10:15:43 +0100 Subject: [PATCH 6/7] More fun :/ --- millw.bat | 60 +++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 40 deletions(-) diff --git a/millw.bat b/millw.bat index cf8beae..cf3aa64 100644 --- a/millw.bat +++ b/millw.bat @@ -23,18 +23,24 @@ set "MILL_REPO_URL=https://github.com/com-lihaoyi/mill" rem %~1% removes surrounding quotes if [%~1%]==[--mill-version] ( + if not [%~2%]==[] ( + set MILL_VERSION=%~2% rem shift command doesn't work within parentheses - if not [%~2%]==[] ( - set MILL_VERSION=%~2% - set "STRIP_VERSION_PARAMS=true" - ) else ( - echo You specified --mill-version without a version. 1>&2 - echo Please provide a version that matches one provided on 1>&2 - echo %MILL_REPO_URL%/releases 1>&2 - exit /b 1 - ) + set "STRIP_VERSION_PARAMS=true" + ) else ( + echo You specified --mill-version without a version. 1>&2 + echo Please provide a version that matches one provided on 1>&2 + echo %MILL_REPO_URL%/releases 1>&2 + exit /b 1 + ) ) +if not defined STRIP_VERSION_PARAMS GOTO AfterStripVersionParams +rem strip the: --mill-version {version} +shift +shift +:AfterStripVersionParams + if [!MILL_VERSION!]==[] ( if exist .mill-version ( set /p MILL_VERSION=<.mill-version @@ -112,7 +118,7 @@ if [!MILL_MAIN_CLI!]==[] ( set "MILL_MAIN_CLI=%0" ) -REM Need to preserve the first position of those listed options +rem Need to preserve the first position of those listed options set MILL_FIRST_ARG= if [%~1%]==[--bsp] ( set MILL_FIRST_ARG=%1% @@ -120,23 +126,18 @@ if [%~1%]==[--bsp] ( ) else ( if [%~1%]==[-i] ( set MILL_FIRST_ARG=%1% - set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--interactive] ( set MILL_FIRST_ARG=%1% - set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--no-server] ( set MILL_FIRST_ARG=%1% - set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--repl] ( set MILL_FIRST_ARG=%1% - set "STRIP_FIRST_ARG=true" ) else ( if [%~1%]==[--help] ( set MILL_FIRST_ARG=%1% - set "STRIP_FIRST_ARG=true" ) ) ) @@ -144,29 +145,8 @@ if [%~1%]==[--bsp] ( ) ) -set MILL_PARAMS=%* - -if defined STRIP_FIRST_ARG ( - if defined STRIP_VERSION_PARAMS ( - for /f "tokens=1-3*" %%a in ("%*") do ( - set MILL_PARAMS=%%d - ) - ) else ( - for /f "tokens=1*" %%a in ("%*") do ( - rem strip %%a - It's the first arg - rem keep %%c - It's the remaining options. - set MILL_PARAMS=%%b - ) - ) -) else ( - if defined STRIP_VERSION_PARAMS ( - for /f "tokens=1-2*" %%a in ("%*") do ( - rem strip %%a - It's the "--mill-version" option. - rem strip %%b - it's the version number that comes after the option. - rem keep %%c - It's the remaining options. - set MILL_PARAMS=%%c - ) - ) -) +if [!MILL_FIRST_ARG!]==[] goto :AfterStripFirstArg +shift +:AfterStripFirstArg -"%MILL%" $MILL_FIRST_ARG% -D "mill.main.cli=%MILL_MAIN_CLI%" %MILL_PARAMS% +"%MILL%" %MILL_FIRST_ARG% -D "mill.main.cli=%MILL_MAIN_CLI%" %*% From 53ddc046861aa84745c58072d29ae58de1b6d8d7 Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 15 Nov 2022 11:05:41 +0100 Subject: [PATCH 7/7] . --- millw.bat | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/millw.bat b/millw.bat index cf3aa64..1ea913c 100644 --- a/millw.bat +++ b/millw.bat @@ -122,7 +122,6 @@ rem Need to preserve the first position of those listed options set MILL_FIRST_ARG= if [%~1%]==[--bsp] ( set MILL_FIRST_ARG=%1% - shift ) else ( if [%~1%]==[-i] ( set MILL_FIRST_ARG=%1% @@ -145,8 +144,27 @@ if [%~1%]==[--bsp] ( ) ) -if [!MILL_FIRST_ARG!]==[] goto :AfterStripFirstArg -shift -:AfterStripFirstArg +set "MILL_PARAMS=%*%" + +if not [!MILL_FIRST_ARG!]==[] ( + if defined STRIP_VERSION_PARAMS ( + for /f "tokens=1-3*" %%a in ("%*") do ( + set "MILL_PARAMS=%%d" + ) + ) else ( + for /f "tokens=1*" %%a in ("%*") do ( + set "MILL_PARAMS=%%b" + ) + ) +) else ( + if defined STRIP_VERSION_PARAMS ( + for /f "tokens=1-2*" %%a in ("%*") do ( + rem strip %%a - It's the "--mill-version" option. + rem strip %%b - it's the version number that comes after the option. + rem keep %%c - It's the remaining options. + set "MILL_PARAMS=%%c" + ) + ) +) -"%MILL%" %MILL_FIRST_ARG% -D "mill.main.cli=%MILL_MAIN_CLI%" %*% +"%MILL%" %MILL_FIRST_ARG% -D "mill.main.cli=%MILL_MAIN_CLI%" %MILL_PARAMS%