33Import-Module - Name (
44 @ (
55 ' command-base.psm1' ,
6+ ' internal\test-parameter-input-object.psm1' ,
67 ' log.psm1'
78 ) |
89 ForEach-Object - Process { Join-Path - Path $PSScriptRoot - ChildPath $_ }
@@ -167,46 +168,35 @@ Value of the output.
167168[Void]
168169#>
169170Function 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' )]
171172 [OutputType ([Void ])]
172173 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 ,
174175 [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 ,
175176 [Parameter (Mandatory = $True , ParameterSetName = ' Single' , Position = 1 , ValueFromPipelineByPropertyName = $True )][AllowEmptyString ()][String ]$Value
176177 )
177178 Begin {
178179 [Boolean ]$Legacy = [String ]::IsNullOrWhiteSpace($Env: GITHUB_OUTPUT )
179180 }
180181 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
203190 }
191+ $InputObject |
192+ Set-Output
193+ Return
204194 }
205195 If ($Legacy ) {
206- Write-GitHubActionsCommand - Command ' set-output' - Parameter @ { ' name' = $ItemName } - Value $ItemValue
196+ Write-GitHubActionsCommand - Command ' set-output' - Parameter @ { ' name' = $Name } - Value $Value
207197 }
208198 Else {
209- Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_OUTPUT - Name $ItemName - Value $ItemValue
199+ Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_OUTPUT - Name $Name - Value $Value
210200 }
211201 }
212202}
@@ -225,46 +215,35 @@ Value of the state.
225215[Void]
226216#>
227217Function 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' )]
229219 [OutputType ([Void ])]
230220 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 ,
232222 [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 ,
233223 [Parameter (Mandatory = $True , ParameterSetName = ' Single' , Position = 1 , ValueFromPipelineByPropertyName = $True )][AllowEmptyString ()][String ]$Value
234224 )
235225 Begin {
236226 [Boolean ]$Legacy = [String ]::IsNullOrWhiteSpace($Env: GITHUB_STATE )
237227 }
238228 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
261237 }
238+ $InputObject |
239+ Set-State
240+ Return
262241 }
263242 If ($Legacy ) {
264- Write-GitHubActionsCommand - Command ' save-state' - Parameter @ { ' name' = $ItemName } - Value $ItemValue
243+ Write-GitHubActionsCommand - Command ' save-state' - Parameter @ { ' name' = $Name } - Value $Value
265244 }
266245 Else {
267- Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_STATE - Name $ItemName - Value $ItemValue
246+ Write-GitHubActionsFileCommand - LiteralPath $Env: GITHUB_STATE - Name $Name - Value $Value
268247 }
269248 }
270249}
0 commit comments