Added help comments to Format command

This commit is contained in:
KevinMarquette
2017-02-05 00:58:49 -08:00
parent baa544d924
commit 8d98ecac3b
4 changed files with 82 additions and 2 deletions

View File

@@ -0,0 +1,29 @@
function Write-ScriptLine
{
param(
[scriptline]
$line,
$WarningAt = [int]::MaxValue,
$ErrorAt = [int]::MaxValue
)
if($line)
{
$Color = 'Green'
if($line.HitCount -eq 0)
{
$Color = 'Gray'
}
elseif($line.Average -ge $ErrorAt)
{
$Color = 'Red'
}
elseif($line.Average -ge $WarningAt)
{
$Color = 'Yellow'
}
Write-Host $line.toString() -ForegroundColor $Color
}
}

View File

@@ -0,0 +1,50 @@
function Format-Chronometer
{
<#
.Description
Generates a report from a Chronometer
.Example
$script = ls C:\workspace\PSGraph\PSGraph -Recurse -Filter *.ps1
$resultes = Get-Chronometer -Path $script.fullname -ScriptBlock {Invoke-Pester C:\workspace\PSGraph}
$results | Format-Chronometer -WarnAt 20 -ErrorAt 200
#>
[cmdletbinding()]
param(
# This is a MonitoredScript object from Get-Chronometer
[Parameter(
ValueFromPipeline=$true
)]
[MonitoredScript[]]
$InputObject,
# 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
)
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
}
}
}
}

Binary file not shown.

View File

@@ -10,7 +10,8 @@ foreach($n in 1..10)
"test string" "test string"
sleep -Milliseconds 3 sleep -Milliseconds 3
} }
sleep -Milliseconds 12 sleep -Milliseconds 12
sleep -Milliseconds 5 sleep -Milliseconds 120
$test = 1+1 $test = 1+1
$test = 1+1 $test = 1+1