Skip to content

Commit ca8ef24

Browse files
author
James Brundage
committed
feat: Stop-HTMX ( Fixes #8 )
1 parent 294b30b commit ca8ef24

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Commands/Stop-Htmx.ps.ps1

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[ValidatePattern('Stop\p{P}+Htmx')]
2+
param()
3+
function Stop-Htmx {
4+
<#
5+
.SYNOPSIS
6+
Stops an htmx server.
7+
.DESCRIPTION
8+
Stops an htmx server running in a background job.
9+
#>
10+
[inherit('Stop-Job', Abstract)]
11+
param()
12+
13+
process {
14+
if ($job) {
15+
if ($job.HttpListener) {
16+
$job.HttpListener.Stop()
17+
}
18+
$job | Stop-Job
19+
} else {
20+
foreach ($existingJob in Get-Job @PSBoundParameters) {
21+
if ($existingJob.HttpListener) {
22+
try {
23+
$existingJob.HttpListener.Stop()
24+
} catch {
25+
Write-Verbose "Failed to stop the listener for job $($existingJob.Id): $_"
26+
}
27+
28+
}
29+
$existingJob | Stop-Job
30+
}
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)