You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
skip console messages if the host is non-interactive
consistent casing for $consoleMessage
Addressed feedback from @HowardWolosky-MSFT and @danbelcher-MSFT by wrapping Write-Host calls with Write-InteractiveHost, so that calls to Write-Host are only forwarded if the host is interactive.
Style feedback from @danbelcher-MSFT
Addressed more style feedback from @HowardWolosky-MSFT, bumped patch version
Addressed last remaining feedback from @HowardWolosky-MSFT
Copy file name to clipboardExpand all lines: StoreBroker/Helpers.ps1
+71-14Lines changed: 71 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -105,7 +105,6 @@ function Wait-JobWithAnimation
105
105
set of configuration options that Wait-Job does.
106
106
#>
107
107
[CmdletBinding()]
108
-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost","", Justification="This function is intended for human interaction, not for scripting. Write-Host makes the most sense for visible feedback.")]
109
108
Param(
110
109
[Parameter(Mandatory)]
111
110
[string] $JobName,
@@ -125,27 +124,27 @@ function Wait-JobWithAnimation
125
124
$iteration=0
126
125
while (((Get-Job-Name $JobName).state -eq'Running'))
Write-Host"`rDONE - Operation took $([int]($iteration/$framesPerSecond)) second(s) $Description"-NoNewline -f Green
134
+
Write-InteractiveHost"`rDONE - Operation took $([int]($iteration/$framesPerSecond)) second(s) $Description"-NoNewline -f Green
136
135
137
136
# We forcibly set Verbose to false here since we don't need it printed to the screen, since we just did above -- we just need to log it.
138
137
Write-Log"DONE - Operation took $([int]($iteration/$framesPerSecond)) second(s) $Description"-Level Verbose -Verbose:$false
139
138
}
140
139
else
141
140
{
142
-
Write-Host"`rDONE (FAILED) - Operation took $([int]($iteration/$framesPerSecond)) second(s) $Description"-NoNewline -f Red
141
+
Write-InteractiveHost"`rDONE (FAILED) - Operation took $([int]($iteration/$framesPerSecond)) second(s) $Description"-NoNewline -f Red
143
142
144
143
# We forcibly set Verbose to false here since we don't need it printed to the screen, since we just did above -- we just need to log it.
145
144
Write-Log"DONE (FAILED) - Operation took $([int]($iteration/$framesPerSecond)) second(s) $Description"-Level Verbose -Verbose:$false
146
145
}
147
146
148
-
Write-Host""
147
+
Write-InteractiveHost""
149
148
}
150
149
151
150
functionFormat-SimpleTableString
@@ -401,7 +400,6 @@ function Write-Log
401
400
[CmdletBinding(SupportsShouldProcess)]
402
401
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess","", Justification="Methods called within here make use of PSShouldProcess, and the switch is passed on to them inherently.")]
403
402
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars","", Justification="We use global variables sparingly and intentionally for module configuration, and employ a consistent naming convention.")]
404
-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost","", Justification="We'd like to use Write-Information instead, but it's not supported on PS 4.0 which we need to support.")]
405
403
param(
406
404
[Parameter(
407
405
Mandatory,
@@ -442,21 +440,21 @@ function Write-Log
442
440
443
441
switch ($Level)
444
442
{
445
-
'Error' { Write-Error$ConsoleMessage }
446
-
'Warning' { Write-Warning$ConsoleMessage }
447
-
'Verbose' { Write-Verbose$ConsoleMessage }
448
-
'Debug' { Write-Debug$ConsoleMessage }
443
+
'Error' { Write-Error$consoleMessage }
444
+
'Warning' { Write-Warning$consoleMessage }
445
+
'Verbose' { Write-Verbose$consoleMessage }
446
+
'Debug' { Write-Debug$consoleMessage }
449
447
'Info' {
450
448
# We'd prefer to use Write-Information to enable users to redirect that pipe if
451
449
# they want, unfortunately it's only available on v5 and above. We'll fallback to
452
450
# using Write-Host for earlier versions (since we still need to support v4).
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost","", Justification="This provides a wrapper around Write-Host. In general, we'd like to use Write-Information, but it's not supported on PS 4.0 which we need to support.")]
0 commit comments