@@ -50,27 +50,16 @@ Function Get-Input {
50
50
Switch ($PSCmdlet.ParameterSetName ) {
51
51
' All' {
52
52
ForEach ($Item In (Get-ChildItem - Path ' Env:\INPUT_*' )) {
53
- If ($Null -ieq $Item.Value ) {
54
- Continue
55
- }
56
- [String ]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim () : $Item.Value
57
- If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0 ) {
58
- Continue
59
- }
60
- $OutputObject [$Item.Name -ireplace ' ^INPUT_' , ' ' ] = $ItemValue
53
+ $OutputObject [$Item.Name -ireplace ' ^INPUT_' , ' ' ] = $Item.Value
61
54
}
62
55
}
63
56
' One' {
64
57
$InputValueRaw = Get-Content - LiteralPath " Env:\INPUT_$ ( $Name.ToUpper ()) " - ErrorAction ' SilentlyContinue'
65
- If ($Null -ieq $InputValueRaw ) {
66
- If ($Mandatory.IsPresent ) {
67
- Write-GitHubActionsFail - Message ($MandatoryMessage -f $Name )
68
- Throw
69
- }
70
- Return
71
- }
72
- [String ]$InputValue = $Trim.IsPresent ? $InputValueRaw.Trim () : $InputValueRaw
73
- If ($EmptyStringAsNull.IsPresent -and $InputValue.Length -ieq 0 ) {
58
+ [String ]$InputValue = $Trim.IsPresent ? ${InputValueRaw} ? .Trim() : $InputValueRaw
59
+ If (
60
+ $Null -ieq $InputValueRaw -or
61
+ ($EmptyStringAsNull.IsPresent -and [String ]::IsNullOrEmpty($InputValue ))
62
+ ) {
74
63
If ($Mandatory.IsPresent ) {
75
64
Write-GitHubActionsFail - Message ($MandatoryMessage -f $Name )
76
65
Throw
@@ -81,27 +70,15 @@ Function Get-Input {
81
70
Return
82
71
}
83
72
' Prefix' {
73
+ [RegEx ]$InputNameReplaceRegEx = " ^INPUT_$ ( [RegEx ]::Escape($NamePrefix )) "
84
74
ForEach ($Item In (Get-ChildItem - Path " Env:\INPUT_$ ( $NamePrefix.ToUpper ()) *" )) {
85
- If ($Null -ieq $Item.Value ) {
86
- Continue
87
- }
88
- [String ]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim () : $Item.Value
89
- If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0 ) {
90
- Continue
91
- }
92
- $OutputObject [$Item.Name -ireplace " ^INPUT_$ ( [RegEx ]::Escape($NamePrefix )) " , ' ' ] = $ItemValue
75
+ $OutputObject [$Item.Name -ireplace $InputNameReplaceRegEx , ' ' ] = $Item.Value
93
76
}
94
77
}
95
78
' Suffix' {
79
+ [RegEx ]$InputNameReplaceRegEx = " ^INPUT_|$ ( [RegEx ]::Escape($NameSuffix )) $"
96
80
ForEach ($Item In (Get-ChildItem - Path " Env:\INPUT_*$ ( $NameSuffix.ToUpper ()) " )) {
97
- If ($Null -ieq $Item.Value ) {
98
- Continue
99
- }
100
- [String ]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim () : $Item.Value
101
- If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0 ) {
102
- Continue
103
- }
104
- $OutputObject [$Item.Name -ireplace " ^INPUT_|$ ( [RegEx ]::Escape($NameSuffix )) $" , ' ' ] = $ItemValue
81
+ $OutputObject [$Item.Name -ireplace $InputNameReplaceRegEx , ' ' ] = $Item.Value
105
82
}
106
83
}
107
84
}
@@ -144,50 +121,31 @@ Function Get-State {
144
121
Switch ($PSCmdlet.ParameterSetName ) {
145
122
' All' {
146
123
ForEach ($Item In (Get-ChildItem - Path ' Env:\STATE_*' )) {
147
- If ($Null -ieq $Item.Value ) {
148
- Continue
149
- }
150
- [String ]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim () : $Item.Value
151
- If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0 ) {
152
- Continue
153
- }
154
- $OutputObject [$Item.Name -ireplace ' ^STATE_' , ' ' ] = $ItemValue
124
+ $OutputObject [$Item.Name -ireplace ' ^STATE_' , ' ' ] = $Item.Value
155
125
}
156
126
}
157
127
' One' {
158
128
$StateValueRaw = Get-Content - LiteralPath " Env:\STATE_$ ( $Name.ToUpper ()) " - ErrorAction ' SilentlyContinue'
159
- If ( $Null -ieq $ StateValueRaw) {
160
- Return
161
- }
162
- [ String ] $StateValue = $Trim .IsPresent ? $StateValueRaw .Trim () : $StateValueRaw
163
- If ( $EmptyStringAsNull .IsPresent -and $StateValue .Length -ieq 0 ) {
129
+ [ String ] $StateValue = $Trim .IsPresent ? ${ StateValueRaw} ? .Trim() : $StateValueRaw
130
+ If (
131
+ $Null -ieq $StateValueRaw -or
132
+ ( $EmptyStringAsNull .IsPresent -and [ String ]::IsNullOrEmpty( $StateValue ))
133
+ ) {
164
134
Return
165
135
}
166
136
Write-Output - InputObject $StateValue
167
137
Return
168
138
}
169
139
' Prefix' {
140
+ [RegEx ]$StateNameReplaceRegEx = " ^STATE_$ ( [RegEx ]::Escape($NamePrefix )) "
170
141
ForEach ($Item In (Get-ChildItem - Path " Env:\STATE_$ ( $NamePrefix.ToUpper ()) *" )) {
171
- If ($Null -ieq $Item.Value ) {
172
- Continue
173
- }
174
- [String ]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim () : $Item.Value
175
- If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0 ) {
176
- Continue
177
- }
178
- $OutputObject [$Item.Name -ireplace " ^STATE_$ ( [RegEx ]::Escape($NamePrefix )) " , ' ' ] = $ItemValue
142
+ $OutputObject [$Item.Name -ireplace $StateNameReplaceRegEx , ' ' ] = $Item.Value
179
143
}
180
144
}
181
145
' Suffix' {
146
+ [RegEx ]$StateNameReplaceRegEx = " ^STATE_|$ ( [RegEx ]::Escape($NameSuffix )) $"
182
147
ForEach ($Item In (Get-ChildItem - Path " Env:\STATE_*$ ( $NameSuffix.ToUpper ()) " )) {
183
- If ($Null -ieq $Item.Value ) {
184
- Continue
185
- }
186
- [String ]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim () : $Item.Value
187
- If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0 ) {
188
- Continue
189
- }
190
- $OutputObject [$Item.Name -ireplace " ^STATE_|$ ( [RegEx ]::Escape($NameSuffix )) $" , ' ' ] = $ItemValue
148
+ $OutputObject [$Item.Name -ireplace $StateNameReplaceRegEx , ' ' ] = $Item.Value
191
149
}
192
150
}
193
151
}
0 commit comments