diff --git a/portable.ps1 b/portable.ps1 index 7712c35..8e4ce16 100644 --- a/portable.ps1 +++ b/portable.ps1 @@ -1,23 +1,15 @@ -param( - [Parameter(Mandatory = $false)] - [string]$EnvName = "default", - - [Parameter(Mandatory = $false)] - [string]$PythonVersion = "3.9", - - [Parameter(Mandatory = $false)] - [string]$RequirementsFile = "", - - [Parameter(Mandatory = $false)] - [switch]$Force, - - [Parameter(Mandatory = $false)] - [switch]$Reinstall -) +$EnvName = "default" +$PythonVersion = "3.9" +$RequirementsFile = "" +$Force = $false +$Reinstall = $false try { - # Clear the console - Clear-Host + # Clear the console only when no command is being executed + if ($args.Count -eq 0) { + Clear-Host + } + # Check for miniforge installer and download if not found if (-not (Test-Path -Path .\miniforge.exe)) { @@ -145,6 +137,19 @@ try { Write-Error "Requirements file $RequirementsFile not found. Skipping requirements installation." } } + + # execute arguments: run any command passed to the script within the prepared environment + if ($args.Count -gt 0) { + $exe = $args[0] + if ($args.Count -gt 1) { + $exeArgs = $args[1..($args.Count - 1)] + & $exe @($exeArgs) + } + else { + & $exe + } + exit $LASTEXITCODE + } } catch { Write-Error "Unexpected error: $_"