@@ -50,27 +50,16 @@ Function Get-Input {
5050 Switch ($PSCmdlet.ParameterSetName ) {
5151 ' All' {
5252 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
6154 }
6255 }
6356 ' One' {
6457 $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+ ) {
7463 If ($Mandatory.IsPresent ) {
7564 Write-GitHubActionsFail - Message ($MandatoryMessage -f $Name )
7665 Throw
@@ -81,27 +70,15 @@ Function Get-Input {
8170 Return
8271 }
8372 ' Prefix' {
73+ [RegEx ]$InputNameReplaceRegEx = " ^INPUT_$ ( [RegEx ]::Escape($NamePrefix )) "
8474 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
9376 }
9477 }
9578 ' Suffix' {
79+ [RegEx ]$InputNameReplaceRegEx = " ^INPUT_|$ ( [RegEx ]::Escape($NameSuffix )) $"
9680 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
10582 }
10683 }
10784 }
@@ -144,50 +121,31 @@ Function Get-State {
144121 Switch ($PSCmdlet.ParameterSetName ) {
145122 ' All' {
146123 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
155125 }
156126 }
157127 ' One' {
158128 $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+ ) {
164134 Return
165135 }
166136 Write-Output - InputObject $StateValue
167137 Return
168138 }
169139 ' Prefix' {
140+ [RegEx ]$StateNameReplaceRegEx = " ^STATE_$ ( [RegEx ]::Escape($NamePrefix )) "
170141 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
179143 }
180144 }
181145 ' Suffix' {
146+ [RegEx ]$StateNameReplaceRegEx = " ^STATE_|$ ( [RegEx ]::Escape($NameSuffix )) $"
182147 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
191149 }
192150 }
193151 }
0 commit comments