Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
Preserve first-position of some essential mill options (#42)
Browse files Browse the repository at this point in the history
Fixes issue com-lihaoyi/mill#2123

Pull request: #42
  • Loading branch information
lefou authored Nov 15, 2022
1 parent f85b829 commit 5dc54a9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 15 deletions.
11 changes: 10 additions & 1 deletion millw
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,20 @@ 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
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}" "$@"
72 changes: 58 additions & 14 deletions millw.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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%

0 comments on commit 5dc54a9

Please sign in to comment.