110110function Add-GHActionsEnvironmentVariable {
111111 [CmdletBinding (DefaultParameterSetName = ' 1' )][OutputType ([void ])]
112112 param (
113- [Parameter (Mandatory = $true , ParameterSetName = ' 1' , Position = 0 , ValueFromPipeline = $true )][Alias (' Input' , ' Object' )]$InputObject ,
113+ [Parameter (Mandatory = $true , ParameterSetName = ' 1' , Position = 0 , ValueFromPipeline = $true )][Alias (' Input' , ' Object' )][ hashtable ] $InputObject ,
114114 [Parameter (Mandatory = $true , ParameterSetName = ' 2' , Position = 0 )][ValidatePattern (' ^[\da-z_]+$' )][Alias (' Key' )][string ]$Name ,
115115 [Parameter (Mandatory = $true , ParameterSetName = ' 2' , Position = 1 )][ValidatePattern (' ^.+$' )][string ]$Value
116116 )
@@ -119,29 +119,20 @@ function Add-GHActionsEnvironmentVariable {
119119 }
120120 process {
121121 switch ($PSCmdlet.ParameterSetName ) {
122- ' 1' {
123- switch ($InputObject.GetType ().Name) {
124- ' Hashtable' {
125- $InputObject.GetEnumerator () | ForEach-Object - Process {
126- if (Test-GHActionsEnvironmentVariable - InputObject " $ ( $_.Name ) =$ ( $_.Value ) " ) {
127- $Result [$_.Name ] = $_.Value
128- }
129- }
130- }
131- ' String' {
132- if (Test-GHActionsEnvironmentVariable - InputObject $InputObject ) {
133- [string []]$InputObjectSplit = $InputObject.Split (' =' )
134- $Result [$InputObjectSplit [0 ]] = $InputObjectSplit [1 ]
135- }
136- }
137- default {
138- Write-Error - Message ' Parameter `InputObject` must be hashtable or string!' - Category InvalidType
139- }
122+ ' 1' { $InputObject.GetEnumerator () | ForEach-Object - Process {
123+ if ($_.Name.GetType ().Name -ne ' string' ) {
124+ Write-Error - Message " Input name `" $ ( $_.Name ) `" must be type of string!" - Category InvalidType
125+ } elseif ($_.Name -notmatch ' ^[\da-z_]+$' ) {
126+ Write-Error - Message " Input name `" $ ( $_.Name ) `" is not match the require pattern!" - Category SyntaxError
127+ } elseif ($_.Value.GetType ().Name -ne ' string' ) {
128+ Write-Error - Message " Input value `" $ ( $_.Value ) `" must be type of string!" - Category InvalidType
129+ } elseif ($_.Value -notmatch ' ^.+$' ) {
130+ Write-Error - Message " Input value `" $ ( $_.Value ) `" is not match the require pattern!" - Category SyntaxError
131+ } else {
132+ $Result [$_.Name ] = $_.Value
140133 }
141- }
142- ' 2' {
143- $Result [$Name ] = $Value
144- }
134+ }; break }
135+ ' 2' { $Result [$Name ] = $Value ; break }
145136 }
146137 }
147138 end {
0 commit comments