110
110
function Add-GHActionsEnvironmentVariable {
111
111
[CmdletBinding (DefaultParameterSetName = ' 1' )][OutputType ([void ])]
112
112
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 ,
114
114
[Parameter (Mandatory = $true , ParameterSetName = ' 2' , Position = 0 )][ValidatePattern (' ^[\da-z_]+$' )][Alias (' Key' )][string ]$Name ,
115
115
[Parameter (Mandatory = $true , ParameterSetName = ' 2' , Position = 1 )][ValidatePattern (' ^.+$' )][string ]$Value
116
116
)
@@ -119,29 +119,20 @@ function Add-GHActionsEnvironmentVariable {
119
119
}
120
120
process {
121
121
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
140
133
}
141
- }
142
- ' 2' {
143
- $Result [$Name ] = $Value
144
- }
134
+ }; break }
135
+ ' 2' { $Result [$Name ] = $Value ; break }
145
136
}
146
137
}
147
138
end {
0 commit comments