Refactor portable.ps1 to simplify parameter handling and enhance command execution. Removed parameter declarations in favor of direct variable assignments, and added conditional console clearing based on argument presence. Improved argument execution logic for running commands within the prepared environment.
This commit is contained in:
41
portable.ps1
41
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: $_"
|
||||
|
||||
Reference in New Issue
Block a user