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

Preserve first-position of some essential mill options #42

Merged
merged 7 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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%