Skip to content

Commit

Permalink
Add CustomSettingsPath parameter to Invoke-PSCodeHealth (in 'HtmlRepo…
Browse files Browse the repository at this point in the history
…rt' parameterset)
  • Loading branch information
MathieuBuisson committed Jul 10, 2017
1 parent 9d86c1b commit de64a0c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions PSCodeHealth/Public/Invoke-PSCodeHealth.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ Function Invoke-PSCodeHealth {
To instruct Invoke-PSCodeHealth to generate an HTML report, and specify the path where the HTML file should be saved.
The path must include the folder path (which has to exist) and the file name.
.PARAMETER CustomSettingsPath
To specify the path of a file containing user-defined compliance rules (metrics thresholds, etc...) in JSON format.
Any compliance rule specified in this file override the default, and rules not specified in this file will use the default from PSCodeHealthSettings.json.
.PARAMETER PassThru
When the parameter HtmlReportPath is used, by default, Invoke-PSCodeHealth doesn't output a [PSCodeHealth.Overall.HealthReport] object to the pipeline.
The PassThru parameter allows to instruct Invoke-PSCodeHealth to output both an HTML report file and a [PSCodeHealth.Overall.HealthReport] object.
Expand All @@ -62,6 +66,15 @@ Function Invoke-PSCodeHealth {
Gets quality and maintainability metrics for code from PowerShell files in the directory C:\GitRepos\MyModule\.
This command will create an HTML report (Report.html) in the current directory and a PSCodeHealth.Overall.HealthReport object to the pipeline.
The styling of HTML elements will reflect their compliance, based on the default compliance rules.
.EXAMPLE
PS C:\> Invoke-PSCodeHealth -Path 'C:\GitRepos\MyModule' -TestsPath 'C:\GitRepos\MyModule\Tests' -HtmlReportPath .\Report.html -CustomSettingsPath .\MySettings.json
Gets quality and maintainability metrics for code from PowerShell files in the directory C:\GitRepos\MyModule\.
This command will create an HTML report (Report.html) in the current directory and a PSCodeHealth.Overall.HealthReport object to the pipeline.
The styling of HTML elements will reflect their compliance, based on the default compliance rules and any custom rules in the file .\MySettings.json.
.OUTPUTS
PSCodeHealth.Overall.HealthReport
Expand Down Expand Up @@ -93,6 +106,10 @@ Function Invoke-PSCodeHealth {
[ValidateScript({ Test-Path -Path (Split-Path $_ -Parent) -PathType Container })]
[string]$HtmlReportPath,

[Parameter(Mandatory=$False, ParameterSetName='HtmlReport')]
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
[string]$CustomSettingsPath,

[Parameter(Mandatory=$False, ParameterSetName='HtmlReport')]
[switch]$PassThru

Expand Down Expand Up @@ -216,6 +233,21 @@ Function Invoke-PSCodeHealth {
}
$HtmlContent = Set-PSCodeHealthPlaceholdersValue -TemplatePath "$PSScriptRoot\..\Assets\HealthReport.html" -PlaceholdersData $HtmlPlaceholders

$ComplianceParams = @{
HealthReport = $HealthReport
}
If ( $PSBoundParameters.ContainsKey('CustomSettingsPath') ) {
$ComplianceParams.Add('CustomSettingsPath', $CustomSettingsPath)
}
$OverallCompliance = Test-PSCodeHealthCompliance @ComplianceParams
If ( $Null -eq $FunctionHealthRecords ) {
$PerFunctionCompliance = $Null
}
Else {
$PerFunctionCompliance = $FunctionHealthRecords.FunctionName.ForEach({ Test-PSCodeHealthCompliance @ComplianceParams -FunctionName $_ })
}
#$ColoredHtmlContent = Set-PSCodeHealthHtmlColor -HealthReport $HealthReport -Compliance $OverallCompliance -PerFunctionCompliance $PerFunctionCompliance

$Null = New-Item -Path $HtmlReportPath -ItemType File -Force
Set-Content -Path $HtmlReportPath -Value $HtmlContent
If ( $PassThru ) {
Expand Down

0 comments on commit de64a0c

Please sign in to comment.