Skip to content

Commit da5f51c

Browse files
author
vp
committed
Refactor kill-dotnet command to remove confirmation prompts for process termination
1 parent a708def commit da5f51c

2 files changed

Lines changed: 5 additions & 19 deletions

File tree

.vscode/tasks-diagnostics.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ${script:DotNetOnly} = $false
5757
function Select-Pid($title){
5858
Import-Module PwshSpectreConsole -ErrorAction Stop
5959
$procs = Get-Process | Where-Object { $_.Id -gt 0 }
60-
if($script:DotNetOnly){ $procs = $procs | Where-Object { $_.ProcessName -match 'dotnet|Presentation.Web.Server' } }
60+
if($script:DotNetOnly){ $procs = $procs | Where-Object { $_.ProcessName -match 'dotnet|' } }
6161
$procs = $procs | Sort-Object ProcessName,Id
6262
$rows = @()
6363
foreach($p in $procs){

.vscode/tasks-misc.ps1

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Commands:
286286
digest|combine-sources|combine|docs Generate consolidated markdown documentation per project (.g.md).
287287
clean|cleanup Remove build/output artifact directories (bin/obj/node_modules/etc.).
288288
repl|shell Run C# REPL (dotnet tool csharprepl) after tool restore.
289-
kill-dotnet Interactive (or non-interactive with -ProcessId) termination of a dotnet process.
289+
kill-dotnet Terminate a dotnet process (interactive selection or direct -ProcessId). No confirmation.
290290
help|? Show this help.
291291
292292
combine-sources Parameters (defaults shown):
@@ -312,8 +312,8 @@ Examples:
312312
pwsh -File .vscode/tasks-misc.ps1 digest -OutputDirectory ./.tmp/docs -StripComments true -StripEmptyLines true
313313
pwsh -File .vscode/tasks-misc.ps1 clean
314314
pwsh -File .vscode/tasks-misc.ps1 repl
315-
pwsh -File .vscode/tasks-misc.ps1 kill-dotnet # interactive selection
316-
pwsh -File .vscode/tasks-misc.ps1 kill-dotnet -ProcessId 1234 -ForceKill # non-interactive
315+
pwsh -File .vscode/tasks-misc.ps1 kill-dotnet # interactive selection (no confirmation)
316+
pwsh -File .vscode/tasks-misc.ps1 kill-dotnet -ProcessId 1234 # direct kill (no confirmation)
317317
318318
Exit Codes:
319319
0 success, non-zero on failure.
@@ -394,21 +394,7 @@ function Kill-DotNetProcess() {
394394
$proc = Get-Process -Id $selectedPid -ErrorAction SilentlyContinue
395395
if(-not $proc){ Write-Host ("Process with PID {0} no longer exists." -f $selectedPid) -ForegroundColor Yellow; $global:LASTEXITCODE=0; return }
396396
Write-Host ("Target: {0} (PID {1})" -f $proc.ProcessName,$selectedPid) -ForegroundColor Cyan
397-
if(-not $ForceKill){
398-
if($ProcessId -gt 0){
399-
$confirmRaw = Read-Host ("Type YES to confirm kill of PID {0} ({1}) or press Enter to cancel" -f $selectedPid,$proc.ProcessName)
400-
if($confirmRaw -ne 'YES'){ Write-Host 'Kill aborted.' -ForegroundColor Yellow; $global:LASTEXITCODE=0; return }
401-
}
402-
elseif(-not $spectreUnavailable){
403-
$confirm = Read-SpectreSelection -Title ("Confirm kill of PID {0} ({1})" -f $selectedPid,$proc.ProcessName) -Choices @('No','Yes') -PageSize 5
404-
if($confirm -ne 'Yes'){ Write-Host 'Kill aborted.' -ForegroundColor Yellow; $global:LASTEXITCODE=0; return }
405-
} else {
406-
$confirmRaw2 = Read-Host ("Type YES to confirm kill of PID {0} ({1})" -f $selectedPid,$proc.ProcessName)
407-
if($confirmRaw2 -ne 'YES'){ Write-Host 'Kill aborted.' -ForegroundColor Yellow; $global:LASTEXITCODE=0; return }
408-
}
409-
} else {
410-
Write-Host 'ForceKill specified; skipping confirmation.' -ForegroundColor DarkYellow
411-
}
397+
# Confirmation omitted per user request; proceed immediately.
412398
try {
413399
Stop-Process -Id $selectedPid -Force -ErrorAction Stop
414400
Write-Host ("Process {0} terminated." -f $selectedPid) -ForegroundColor Green

0 commit comments

Comments
 (0)