Skip to content

Commit f6eb7aa

Browse files
authored
Improve path enhancement handling in lib_path.cmd
Refactor path enhancement logic for clarity and robustness.
1 parent 6f6c21d commit f6eb7aa

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

vendor/lib/lib_path.cmd

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ exit /b
9191

9292
if /i "!position!" == "append" (
9393
if "!found!" == "0" (
94-
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!\"$"
94+
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!$"
9595
call :set_found
9696
)
9797
%print_debug% :enhance_path "Env Var END PATH !find_query! - found=!found!"
9898
) else (
9999
if "!found!" == "0" (
100-
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:"^\"!find_query!;"
100+
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:"^!find_query!;"
101101
call :set_found
102102
)
103103
%print_debug% :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
@@ -190,13 +190,28 @@ exit /b
190190
exit /b 1
191191
)
192192

193+
rem Parse arguments robustly:
194+
rem Accept either public form: "[dir_path]" [max_depth] [append]
195+
rem or internal recursive form: "[dir_path]" [depth] [max_depth] [append]
193196
set "depth=%~2"
194197
set "max_depth=%~3"
198+
set "position="
195199

196-
if "%~4" neq "" if /i "%~4" == "append" (
197-
set "position=%~4"
198-
) else (
199-
set "position="
200+
if /i "%~4" == "append" set "position=append"
201+
if /i "%~3" == "append" (
202+
set "position=append"
203+
set "max_depth="
204+
)
205+
206+
if not defined depth set "depth=0"
207+
if not defined max_depth (
208+
if defined depth (
209+
rem If only one numeric argument provided, treat it as max_depth
210+
set "max_depth=%depth%"
211+
set "depth=0"
212+
) else (
213+
set "max_depth=1"
214+
)
200215
)
201216

202217
dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL
@@ -232,8 +247,6 @@ exit /b
232247
call :loop_depth
233248
)
234249

235-
set "PATH=%PATH%"
236-
237250
exit /b
238251

239252
:set_depth

0 commit comments

Comments
 (0)