From aa2b1f7854ab5aae6caf90372ccdf4d459f82d1c Mon Sep 17 00:00:00 2001 From: KevinMarquette Date: Tue, 7 Feb 2017 01:33:23 -0800 Subject: [PATCH 1/2] Made format function more flexible --- Chronometer/Public/Format-Chronometer.ps1 | 38 ++++++++++++++--------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/Chronometer/Public/Format-Chronometer.ps1 b/Chronometer/Public/Format-Chronometer.ps1 index f12be7e..38f41d8 100644 --- a/Chronometer/Public/Format-Chronometer.ps1 +++ b/Chronometer/Public/Format-Chronometer.ps1 @@ -18,33 +18,43 @@ function Format-Chronometer [MonitoredScript[]] $InputObject, + # This is a ScriptLine object from a MonitoredScript object + [Parameter( + ValueFromPipeline=$true + )] + [ScriptLine[]] + $Line, + # If the average time of a command is more than this, the output is yellow [int] $WarningAt = 20, #If the average time of a comamand is more than this, the output is red [int] - $ErrorAt = 200 + $ErrorAt = 200, + + # Forces the report to show scripts with no execution time + [switch] + $ShowAll ) - begin { - $green = @{ForgroundColor='green'} - $grey = @{ForgroundColor='grey'} - $yellow = @{ForgroundColor='grey'} - $yellow = @{ForgroundColor='grey'} - $yellow = @{ForgroundColor='grey'} - } process { foreach($script in $InputObject) { - Write-Host '' - Write-Host "Script: $($script.Path)" -ForegroundColor Green - Write-Host "Execution Time: $($script.ExecutionTime)" -ForegroundColor Green - foreach($line in $script.line) - { - Write-ScriptLine $line -WarningAt $WarningAt -ErrorAt $ErrorAt + if($script.ExecutionTime -ne [TimeSpan]::Zero -or $ShowAll) + { + Write-Host '' + Write-Host "Script: $($script.Path)" -ForegroundColor Green + Write-Host "Execution Time: $($script.ExecutionTime)" -ForegroundColor Green + + $script.line | Format-Chronometer -WarningAt $WarningAt -ErrorAt $ErrorAt } } + + foreach($command in $Line) + { + Write-ScriptLine $line -WarningAt $WarningAt -ErrorAt $ErrorAt + } } } From 20ce11316987488fb6784dc0528cceb5a8052fa6 Mon Sep 17 00:00:00 2001 From: KevinMarquette Date: Tue, 7 Feb 2017 01:44:33 -0800 Subject: [PATCH 2/2] Adjusted arguments skip ci --- Chronometer/Public/Format-Chronometer.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Chronometer/Public/Format-Chronometer.ps1 b/Chronometer/Public/Format-Chronometer.ps1 index 38f41d8..ccb3211 100644 --- a/Chronometer/Public/Format-Chronometer.ps1 +++ b/Chronometer/Public/Format-Chronometer.ps1 @@ -9,18 +9,20 @@ function Format-Chronometer $resultes = Get-Chronometer -Path $script.fullname -ScriptBlock {Invoke-Pester C:\workspace\PSGraph} $results | Format-Chronometer -WarnAt 20 -ErrorAt 200 #> - [cmdletbinding()] + [cmdletbinding(DefaultParameterSetName='Script')] param( # This is a MonitoredScript object from Get-Chronometer [Parameter( - ValueFromPipeline=$true + ValueFromPipeline=$true, + ParameterSetName='Script' )] [MonitoredScript[]] $InputObject, # This is a ScriptLine object from a MonitoredScript object [Parameter( - ValueFromPipeline=$true + ValueFromPipeline=$true, + ParameterSetName='Line' )] [ScriptLine[]] $Line, @@ -54,7 +56,7 @@ function Format-Chronometer foreach($command in $Line) { - Write-ScriptLine $line -WarningAt $WarningAt -ErrorAt $ErrorAt + Write-ScriptLine $command -WarningAt $WarningAt -ErrorAt $ErrorAt } } }