3
3
Import-Module - Name (
4
4
@ (
5
5
' command-base.psm1' ,
6
+ ' internal\test-parameter-input-object.psm1' ,
6
7
' log.psm1'
7
8
) |
8
9
ForEach-Object - Process { Join-Path - Path $PSScriptRoot - ChildPath $_ }
@@ -167,46 +168,35 @@ Value of the output.
167
168
[Void]
168
169
#>
169
170
Function Set-Output {
170
- [CmdletBinding (DefaultParameterSetName = ' Multiple ' , HelpUri = ' https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_set-githubactionsoutput#Set-GitHubActionsOutput' )]
171
+ [CmdletBinding (DefaultParameterSetName = ' Single ' , HelpUri = ' https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_set-githubactionsoutput#Set-GitHubActionsOutput' )]
171
172
[OutputType ([Void ])]
172
173
Param (
173
- [Parameter (Mandatory = $True , ParameterSetName = ' Multiple' , Position = 0 , ValueFromPipeline = $True )][Alias (' Input' , ' Object' )][ Hashtable ]$InputObject ,
174
+ [Parameter (Mandatory = $True , ParameterSetName = ' Multiple' , Position = 0 , ValueFromPipeline = $True )][ValidateScript ({ Test-GitHubActionsParameterInputObject - InputObject $_ })][ Alias (' Input' , ' Object' )]$InputObject ,
174
175
[Parameter (Mandatory = $True , ParameterSetName = ' Single' , Position = 0 , ValueFromPipelineByPropertyName = $True )][ValidatePattern (' ^(?:[\da-z][\da-z_-]*)?[\da-z]$' , ErrorMessage = ' `{0}` is not a valid GitHub Actions output name!' )][Alias (' Key' )][String ]$Name ,
175
176
[Parameter (Mandatory = $True , ParameterSetName = ' Single' , Position = 1 , ValueFromPipelineByPropertyName = $True )][AllowEmptyString ()][String ]$Value
176
177
)
177
178
Begin {
178
179
[Boolean ]$Legacy = [String ]::IsNullOrWhiteSpace($Env: GITHUB_OUTPUT )
179
180
}
180
181
Process {
181
- Switch ($PSCmdlet.ParameterSetName ) {
182
- ' Multiple' {
183
- ForEach ($Item In $InputObject.GetEnumerator ()) {
184
- If ($Item.Name.GetType ().Name -ine ' String' ) {
185
- Write-Error - Message ' Parameter `Name` must be type of string!' - Category ' InvalidType'
186
- Return
187
- }
188
- If ($Item.Name -inotmatch ' ^(?:[\da-z][\da-z_-]*)?[\da-z]$' ) {
189
- Write-Error - Message " `` $ ( $Item.Name ) `` is not a valid GitHub Actions output name!" - Category ' SyntaxError'
190
- Return
191
- }
192
- If ($Item.Value.GetType ().Name -ine ' String' ) {
193
- Write-Error - Message ' Parameter `Value` must be type of string!' - Category ' InvalidType'
194
- Return
195
- }
196
- [String ]$ItemName = $Item.Name
197
- [String ]$ItemValue = $Item.Value
198
- }
199
- }
200
- ' Single' {
201
- [String ]$ItemName = $Name
202
- [String ]$ItemValue = $Value
182
+ If ($PSCmdlet.ParameterSetName -ieq ' Multiple' ) {
183
+ If (
184
+ $InputObject -is [Hashtable ] -or
185
+ $InputObject -is [System.Collections.Specialized.OrderedDictionary ]
186
+ ) {
187
+ $InputObject.GetEnumerator () |
188
+ Set-Output
189
+ Return
203
190
}
191
+ $InputObject |
192
+ Set-Output
193
+ Return
204
194
}
205
195
If ($Legacy ) {
206
- Write-GitHubActionsCommand - Command ' set-output' - Parameter @ { ' name' = $ItemName } - Value $ItemValue
196
+ Write-GitHubActionsCommand - Command ' set-output' - Parameter @ { ' name' = $Name } - Value $Value
207
197
}
208
198
Else {
209
- Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_OUTPUT - Name $ItemName - Value $ItemValue
199
+ Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_OUTPUT - Name $Name - Value $Value
210
200
}
211
201
}
212
202
}
@@ -225,46 +215,35 @@ Value of the state.
225
215
[Void]
226
216
#>
227
217
Function Set-State {
228
- [CmdletBinding (DefaultParameterSetName = ' Multiple ' , HelpUri = ' https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_set-githubactionsstate#Set-GitHubActionsState' )]
218
+ [CmdletBinding (DefaultParameterSetName = ' Single ' , HelpUri = ' https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_set-githubactionsstate#Set-GitHubActionsState' )]
229
219
[OutputType ([Void ])]
230
220
Param (
231
- [Parameter (Mandatory = $True , ParameterSetName = ' Multiple' , Position = 0 , ValueFromPipeline = $True )][Alias (' Input' , ' Object' )][ Hashtable ]$InputObject ,
221
+ [Parameter (Mandatory = $True , ParameterSetName = ' Multiple' , Position = 0 , ValueFromPipeline = $True )][ValidateScript ({ Test-GitHubActionsParameterInputObject - InputObject $_ })][ Alias (' Input' , ' Object' )]$InputObject ,
232
222
[Parameter (Mandatory = $True , ParameterSetName = ' Single' , Position = 0 , ValueFromPipelineByPropertyName = $True )][ValidatePattern (' ^(?:[\da-z][\da-z_-]*)?[\da-z]$' , ErrorMessage = ' `{0}` is not a valid GitHub Actions state name!' )][Alias (' Key' )][String ]$Name ,
233
223
[Parameter (Mandatory = $True , ParameterSetName = ' Single' , Position = 1 , ValueFromPipelineByPropertyName = $True )][AllowEmptyString ()][String ]$Value
234
224
)
235
225
Begin {
236
226
[Boolean ]$Legacy = [String ]::IsNullOrWhiteSpace($Env: GITHUB_STATE )
237
227
}
238
228
Process {
239
- Switch ($PSCmdlet.ParameterSetName ) {
240
- ' Multiple' {
241
- ForEach ($Item In $InputObject.GetEnumerator ()) {
242
- If ($Item.Name.GetType ().Name -ine ' String' ) {
243
- Write-Error - Message ' Parameter `Name` must be type of string!' - Category ' InvalidType'
244
- Return
245
- }
246
- If ($Item.Name -inotmatch ' ^(?:[\da-z][\da-z_-]*)?[\da-z]$' ) {
247
- Write-Error - Message " `` $ ( $Item.Name ) `` is not a valid GitHub Actions state name!" - Category ' SyntaxError'
248
- Return
249
- }
250
- If ($Item.Value.GetType ().Name -ine ' String' ) {
251
- Write-Error - Message ' Parameter `Value` must be type of string!' - Category ' InvalidType'
252
- Return
253
- }
254
- [String ]$ItemName = $Item.Name
255
- [String ]$ItemValue = $Item.Value
256
- }
257
- }
258
- ' Single' {
259
- [String ]$ItemName = $Name
260
- [String ]$ItemValue = $Value
229
+ If ($PSCmdlet.ParameterSetName -ieq ' Multiple' ) {
230
+ If (
231
+ $InputObject -is [Hashtable ] -or
232
+ $InputObject -is [System.Collections.Specialized.OrderedDictionary ]
233
+ ) {
234
+ $InputObject.GetEnumerator () |
235
+ Set-State
236
+ Return
261
237
}
238
+ $InputObject |
239
+ Set-State
240
+ Return
262
241
}
263
242
If ($Legacy ) {
264
- Write-GitHubActionsCommand - Command ' save-state' - Parameter @ { ' name' = $ItemName } - Value $ItemValue
243
+ Write-GitHubActionsCommand - Command ' save-state' - Parameter @ { ' name' = $Name } - Value $Value
265
244
}
266
245
Else {
267
- Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_STATE - Name $ItemName - Value $ItemValue
246
+ Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_STATE - Name $Name - Value $Value
268
247
}
269
248
}
270
249
}
0 commit comments