Skip to content

Commit 8ece000

Browse files
committed
Added parameter validation in the elixir.bat file
The batch file now allows both erlang and elixir commands before the ".ex" file; if any unknown parameter is passed before the ".ex file", an error is thrown.
1 parent c7a2442 commit 8ece000

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

bin/elixir.bat

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@echo off
2+
SETLOCAL enabledelayedexpansion
23
set argc=0
34
for %%x in (%*) do set /A argc+=1
45
if %argc%== 0 (
@@ -25,20 +26,24 @@ goto :EOF
2526

2627
:parseopts
2728

28-
rem parameters for Erlang
29+
rem Parameters for Erlang
2930
set parsErlang=
3031

31-
rem make sure we keep a copy of all parameters
32+
rem Make sure we keep a copy of all parameters
3233
set allPars=%*
3334

34-
rem Recursive loop called for each parameter
35+
rem Optional parameters before the "-extra" parameter
36+
set beforeExtra=
37+
38+
rem Recursive loop called for each parameter that parses the cmd line parameters
3539
:startloop
3640
set par=%1
3741
shift
3842
if "%par%"=="" (
3943
rem if no parameters defined
4044
goto :run
4145
)
46+
rem ******* ERLANG PARAMETERS **********************
4247
for /f "usebackq" %%m in (`echo %par%^|findstr \--detached`) do (
4348
set parsErlang=%parsErlang% -detached
4449
goto:startloop
@@ -62,6 +67,45 @@ for /f "usebackq" %%m in (`echo %par%^|findstr \--name`) do (
6267
shift
6368
goto:startloop
6469
)
65-
goto:startloop
70+
for /f "usebackq" %%m in (`echo %par%^|findstr \--erl`) do (
71+
set beforeExtra=%beforeExtra% %~1
72+
shift
73+
goto:startloop
74+
)
75+
rem ******* elixir parameters **********************
76+
for /f "usebackq" %%m in (`echo %par%^|findstr \--v`) do (
77+
goto:startloop
78+
)
79+
for /f "usebackq" %%m in (`echo %par%^|findstr \--compile`) do (
80+
goto:startloop
81+
)
82+
for /f "usebackq" %%m in (`echo %par%^|findstr \--no-halt`) do (
83+
goto:startloop
84+
)
85+
for /f "usebackq" %%m in (`echo %par%^|findstr \+iex`) do (
86+
goto:startloop
87+
)
88+
for /f "usebackq" %%m in (`echo %par%^|findstr \+compile`) do (
89+
goto:startloop
90+
)
91+
for /f "usebackq" %%m in (`echo %par%^|findstr \-[erS]`) do (
92+
shift
93+
goto:startloop
94+
)
95+
for /f "usebackq" %%m in (`echo %par%^|findstr \-p[raz]`) do (
96+
shift
97+
goto:startloop
98+
)
99+
for /f "usebackq" %%m in (`echo %par%^|findstr \--remsh`) do (
100+
shift
101+
goto:startloop
102+
)
103+
rem ******* elixir file **********************
104+
for /f "usebackq" %%m in (`echo %par%^|findstr \.ex`) do (
105+
goto:run
106+
)
107+
REM Others should give a problem
108+
echo ERROR: Parameter %par% is not allowed before the .ex file
109+
exit /B -1
66110
:run
67-
erl -env ERL_LIBS %ERL_LIBS%;"%~dp0\..\lib" -noshell %ELIXIR_ERL_OPTS% %parsErlang% -s elixir start_cli -extra %allPars%
111+
echo erl -env ERL_LIBS %ERL_LIBS%;"%~dp0\..\lib" -noshell %ELIXIR_ERL_OPTS% %parsErlang% -s elixir start_cli %beforeExtra% -extra %*

0 commit comments

Comments
 (0)