Skip to content

Commit f5bb85e

Browse files
StartAutomatingStartAutomating
StartAutomating
authored and
StartAutomating
committed
feat: Stop-HTMX ( Fixes #8 )
1 parent ca8ef24 commit f5bb85e

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

Commands/Stop-Htmx.ps1

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
[ValidatePattern('Stop\p{P}+Htmx')]
2+
param()
3+
function Stop-Htmx {
4+
<#
5+
6+
.SYNOPSIS
7+
Stops an htmx server.
8+
.DESCRIPTION
9+
Stops an htmx server running in a background job.
10+
11+
#>
12+
13+
14+
param(
15+
[Parameter(ParameterSetName='JobParameterSet', Mandatory=$true, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
16+
[ValidateNotNullOrEmpty()]
17+
[System.Management.Automation.Job[]]
18+
${Job},
19+
20+
[switch]
21+
${PassThru},
22+
23+
[Parameter(ParameterSetName='NameParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
24+
[ValidateNotNullOrEmpty()]
25+
[string[]]
26+
${Name},
27+
28+
[Parameter(ParameterSetName='InstanceIdParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
29+
[ValidateNotNullOrEmpty()]
30+
[guid[]]
31+
${InstanceId},
32+
33+
[Parameter(ParameterSetName='SessionIdParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
34+
[ValidateNotNullOrEmpty()]
35+
[int[]]
36+
${Id},
37+
38+
[Parameter(ParameterSetName='StateParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
39+
[System.Management.Automation.JobState]
40+
${State},
41+
42+
[Parameter(ParameterSetName='FilterParameterSet', Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
43+
[ValidateNotNullOrEmpty()]
44+
[hashtable]
45+
${Filter}
46+
)
47+
dynamicParam {
48+
$baseCommand =
49+
if (-not $script:StopJob) {
50+
$script:StopJob =
51+
$executionContext.SessionState.InvokeCommand.GetCommand('Stop-Job','Cmdlet')
52+
$script:StopJob
53+
} else {
54+
$script:StopJob
55+
}
56+
$IncludeParameter = @()
57+
$ExcludeParameter = @()
58+
59+
}
60+
process {
61+
if ($job) {
62+
if ($job.HttpListener) {
63+
$job.HttpListener.Stop()
64+
}
65+
$job | Stop-Job
66+
} else {
67+
foreach ($existingJob in Get-Job @PSBoundParameters) {
68+
if ($existingJob.HttpListener) {
69+
try {
70+
$existingJob.HttpListener.Stop()
71+
} catch {
72+
Write-Verbose "Failed to stop the listener for job $($existingJob.Id): $_"
73+
}
74+
75+
}
76+
$existingJob | Stop-Job
77+
}
78+
}
79+
80+
}
81+
}
82+

0 commit comments

Comments
 (0)