增加 Windows 脚本交互菜单
This commit is contained in:
+35
-1
@@ -4,7 +4,7 @@
|
||||
param(
|
||||
[Parameter(Position = 0)]
|
||||
[ValidateSet('start', 'update')]
|
||||
[string]$Action = 'start',
|
||||
[string]$Action,
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$ListenAddress = '0.0.0.0',
|
||||
@@ -62,6 +62,26 @@ function Invoke-NativeCommand {
|
||||
}
|
||||
}
|
||||
|
||||
function Select-InteractiveAction {
|
||||
Write-Host ''
|
||||
Write-Host 'Web Tools'
|
||||
Write-Host ' [1] Start current build (no update)'
|
||||
Write-Host ' [2] Update from Git, rebuild, and start'
|
||||
Write-Host ' [3] Update from Git and rebuild only'
|
||||
Write-Host ' [0] Exit'
|
||||
|
||||
while ($true) {
|
||||
$selection = (Read-Host 'Select an action (0-3)').Trim()
|
||||
switch ($selection) {
|
||||
'1' { return 'start' }
|
||||
'2' { return 'update' }
|
||||
'3' { return 'update-no-start' }
|
||||
'0' { return 'exit' }
|
||||
default { Write-Warning 'Invalid selection. Enter 0, 1, 2, or 3.' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-ProductionBuild {
|
||||
if (-not (Test-Path -LiteralPath $serverEntry -PathType Leaf)) {
|
||||
throw "Server entry was not found: $serverEntry"
|
||||
@@ -166,6 +186,20 @@ function Start-WebTools {
|
||||
}
|
||||
}
|
||||
|
||||
if (-not $PSBoundParameters.ContainsKey('Action')) {
|
||||
$interactiveAction = Select-InteractiveAction
|
||||
if ($interactiveAction -eq 'exit') {
|
||||
return
|
||||
}
|
||||
if ($interactiveAction -eq 'update-no-start') {
|
||||
$Action = 'update'
|
||||
$NoStart = $true
|
||||
}
|
||||
else {
|
||||
$Action = $interactiveAction
|
||||
}
|
||||
}
|
||||
|
||||
if ($Action -eq 'start' -and $NoStart) {
|
||||
throw "-NoStart can only be used with the 'update' action."
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user