diff --git a/millw b/millw index d93110a..bddfcd4 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" ] || [ "$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 +fi + unset MILL_DOWNLOAD_PATH unset MILL_OLD_DOWNLOAD_PATH unset OLD_MILL @@ -176,4 +183,6 @@ unset MILL_VERSION unset MILL_VERSION_TAG unset MILL_REPO_URL -exec "${MILL}" -D "mill.main.cli=${MILL_MAIN_CLI}" "$@" +# 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}" "$@" diff --git a/millw.bat b/millw.bat index 69f6773..1ea913c 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 @@ -108,19 +114,57 @@ set MILL_DOWNLOAD_PATH= set MILL_VERSION= set MILL_REPO_URL= -set MILL_PARAMS=%* - if [!MILL_MAIN_CLI!]==[] ( set "MILL_MAIN_CLI=%0" ) -if defined STRIP_VERSION_PARAMS ( +rem Need to preserve the first position of those listed options +set MILL_FIRST_ARG= +if [%~1%]==[--bsp] ( + set MILL_FIRST_ARG=%1% +) else ( + if [%~1%]==[-i] ( + set MILL_FIRST_ARG=%1% + ) else ( + if [%~1%]==[--interactive] ( + set MILL_FIRST_ARG=%1% + ) else ( + if [%~1%]==[--no-server] ( + set MILL_FIRST_ARG=%1% + ) else ( + if [%~1%]==[--repl] ( + set MILL_FIRST_ARG=%1% + ) else ( + if [%~1%]==[--help] ( + set MILL_FIRST_ARG=%1% + ) + ) + ) + ) + ) +) + +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 + set "MILL_PARAMS=%%c" ) + ) ) -"%MILL%" -D "mill.main.cli=%MILL_MAIN_CLI%" %MILL_PARAMS% +"%MILL%" %MILL_FIRST_ARG% -D "mill.main.cli=%MILL_MAIN_CLI%" %MILL_PARAMS%