| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Sets the name and/or description of a task. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function sets the human-friendly name and/or description of a task identified by its id. |
| | | 6 | | .PARAMETER Server |
| | | 7 | | The Kestrun server instance. |
| | | 8 | | .PARAMETER Id |
| | | 9 | | The id of the task to update. This parameter is mandatory. |
| | | 10 | | .PARAMETER Name |
| | | 11 | | The new name for the task. This parameter is optional but at least one of Name or Description must be provided. |
| | | 12 | | .PARAMETER Description |
| | | 13 | | The new description for the task. This parameter is optional but at least one of Name or Description must be provide |
| | | 14 | | .EXAMPLE |
| | | 15 | | Set-KrTaskName -Id 'task-id' -Name 'My Task' |
| | | 16 | | This command sets the name of the specified task to 'My Task'. |
| | | 17 | | .EXAMPLE |
| | | 18 | | Set-KrTaskName -Id 'task-id' -Description 'This is a sample task.' |
| | | 19 | | This command sets the description of the specified task. |
| | | 20 | | .EXAMPLE |
| | | 21 | | Set-KrTaskName -Id 'task-id' -Name 'My Task' -Description 'This is a sample task.' |
| | | 22 | | This command sets both the name and description of the specified task. |
| | | 23 | | .NOTES |
| | | 24 | | At least one of the Name or Description parameters must be provided and non-empty. |
| | | 25 | | If the specified task id does not exist, an error will be thrown. |
| | | 26 | | #> |
| | | 27 | | function Set-KrTaskName { |
| | | 28 | | [KestrunRuntimeApi('Everywhere')] |
| | | 29 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 30 | | param( |
| | | 31 | | [Parameter(ValueFromPipeline = $true)] |
| | | 32 | | [Kestrun.Hosting.KestrunHost]$Server, |
| | | 33 | | |
| | | 34 | | [Parameter(mandatory = $true)] |
| | | 35 | | [string]$Id, |
| | | 36 | | |
| | | 37 | | [Parameter(Mandatory = $false)] |
| | | 38 | | [string]$Name, |
| | | 39 | | |
| | | 40 | | [parameter(Mandatory = $false)] |
| | | 41 | | [string]$Description |
| | | 42 | | ) |
| | | 43 | | begin { |
| | 0 | 44 | | $Server = Resolve-KestrunServer -Server $Server |
| | | 45 | | } |
| | | 46 | | process { |
| | 0 | 47 | | if ([string]::IsNullOrWhiteSpace($Name) -and [string]::IsNullOrWhiteSpace($Description)) { |
| | 0 | 48 | | throw [System.ArgumentException] 'Either Name or Description must be provided and non-empty.' |
| | | 49 | | } |
| | 0 | 50 | | if ($PSBoundParameters.ContainsKey('Name')) { |
| | 0 | 51 | | $Server.Tasks.SetTaskName($Id, $Name) |
| | | 52 | | } |
| | 0 | 53 | | if ($PSBoundParameters.ContainsKey('Description')) { |
| | 0 | 54 | | $Server.Tasks.SetTaskDescription($Id, $Description) |
| | | 55 | | } |
| | | 56 | | } |
| | | 57 | | } |