1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-15 00:35:07 +00:00

fix(windows): fix CLI argument passing for switches like -DryRun

- Fix mole.cmd batch launcher to properly pass switch arguments
- Store %~dp0 before parse loop to avoid expansion issues
- Use PowerShell splatting in Invoke-MoleCommand for proper switch handling
- Rename $script:DryRun to $script:MoleDryRunMode in file_ops.ps1 to avoid
  variable shadowing when dot-sourcing
- Handle switches passed as strings (e.g., '-ShowHelp') in mole.ps1 Main()

Fixes issue where 'mole clean -DryRun' would run cleanup instead of preview.
This commit is contained in:
Bhadra
2026-01-08 18:08:59 +05:30
parent 230ca07c7f
commit 3ebaeefa18
3 changed files with 86 additions and 19 deletions

View File

@@ -294,9 +294,22 @@ function Install-Mole {
}
# Create launcher batch file for easier access
# Note: Store %~dp0 immediately to avoid issues with delayed expansion in the parse loop
$batchContent = @"
@echo off
powershell.exe -ExecutionPolicy Bypass -NoLogo -File "%~dp0mole.ps1" %*
setlocal EnableDelayedExpansion
rem Store the script directory immediately before any shifting
set "MOLE_DIR=%~dp0"
set "ARGS="
:parse
if "%~1"=="" goto run
set "ARGS=!ARGS! '%~1'"
shift
goto parse
:run
powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "& '%MOLE_DIR%mole.ps1' !ARGS!"
"@
$batchPath = Join-Path $InstallDir "mole.cmd"
Set-Content -Path $batchPath -Value $batchContent -Encoding ASCII