Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 85e6783

Browse files
authored
Merge pull request #334 from X-Guardian/PowerShellHelp-OutputPath-Fix
New-DscResourcePowerShellHelp: Restore OutputPath parameter
2 parents e3ef63b + 4be2b0b commit 85e6783

File tree

3 files changed

+135
-15
lines changed

3 files changed

+135
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
file that do not exist in the en-US resource file.
5555
- Added `Publish-WikiContent` helper function to publish auto-generated Wiki files
5656
to the relevant DSC resource GitHub Wiki ([issue #142](https://github.com/PowerShell/DscResource.Tests/issues/142)).
57-
- Update New-DscResourcePowerShellHelp to output the PowerShell help files to
57+
- Update New-DscResourcePowerShellHelp to optionally output the PowerShell help files to
5858
the resource specific path and fix the example processing.
5959
- Added processing to `Test-PublishMetaData` for the InvalidGUID error from Test-ScriptFileInfo
6060
([issue #330](https://github.com/PowerShell/DscResource.Tests/issues/330)).

DscResource.DocumentationHelper/PowerShellHelp.psm1

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,28 @@ $script:localizedData = Get-LocalizedData -ModuleName $moduleName -ModuleRoot $P
2525

2626
<#
2727
.SYNOPSIS
28-
2928
New-DscResourcePowerShellHelp generates PowerShell compatible help files for a DSC
3029
resource module
3130
3231
.DESCRIPTION
33-
3432
The New-DscResourcePowerShellHelp cmdlet will review all of the MOF based resources
35-
in a specified module directory and will inject PowerShell help files for each resource
36-
in to the resource's subdirectory. These help files include details on the property types for
37-
each resource, as well as a text description and examples where they exist.
38-
a README.md with a text description must exist in the resource's subdirectory for the
33+
in a specified module directory and will inject PowerShell help files for each resource.
34+
These help files include details on the property types for each resource, as well as a text
35+
description and examples where they exist.
36+
37+
The help files are output to the OutputPath directory if specified, or if not, they are
38+
output to the releveant resource's 'en-US' directory.
39+
40+
A README.md with a text description must exist in the resource's subdirectory for the
3941
help file to be generated.
42+
4043
These help files can then be read by passing the name of the resource as a parameter to Get-Help.
4144
4245
.PARAMETER ModulePath
43-
4446
The path to the root of the DSC resource module (where the PSD1 file is found, not the folder for
4547
each individual DSC resource)
4648
4749
.EXAMPLE
48-
4950
This example shows how to generate help for a specific module
5051
5152
New-DscResourcePowerShellHelp -ModulePath C:\repos\SharePointdsc
@@ -58,7 +59,11 @@ function New-DscResourcePowerShellHelp
5859
(
5960
[parameter(Mandatory = $true)]
6061
[System.String]
61-
$ModulePath
62+
$ModulePath,
63+
64+
[parameter()]
65+
[System.String]
66+
$OutputPath
6267
)
6368

6469
Import-Module (Join-Path -Path $PSScriptRoot -ChildPath 'MofHelper.psm1') -Verbose:$false
@@ -135,7 +140,16 @@ function New-DscResourcePowerShellHelp
135140
Write-Warning -Message ($script:localizedData.NoExampleFileFoundWarning -f $result.FriendlyName)
136141
}
137142

138-
$savePath = Join-Path -Path $mofFileObject.DirectoryName -ChildPath "\en-US\about_$($result.FriendlyName).help.txt"
143+
# Output to $OutputPath if specified or the resource 'en-US' directory if not.
144+
$outputFileName = "about_$($result.FriendlyName).help.txt"
145+
if ($OutputPath)
146+
{
147+
$savePath = Join-Path -Path $OutputPath -ChildPath $outputFileName
148+
}
149+
else
150+
{
151+
$savePath = Join-Path -Path $mofFileObject.DirectoryName -ChildPath 'en-US' | Join-Path -ChildPath $outputFileName
152+
}
139153
Write-Verbose -Message ($script:localizedData.OutputHelpDocumentMessage -f $savePath)
140154
$output | Out-File -FilePath $savePath -Encoding utf8 -Force
141155
}

Tests/Unit/DscResource.DocumentationHelper.Tests.ps1

Lines changed: 110 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ Configuration CertificateExport_CertByFriendlyName_Config
924924
$mockGitUserEmail = '[email protected]'
925925
$mockGitUserName = 'mock'
926926
$mockGithubAccessToken = '1234567890'
927-
$mockPath = "C:\Windows\Temp"
927+
$mockPath = $env:temp
928928
$mockJobId = 'imy2wgh1ylo9qcpb'
929929
$mockBuildVersion = '2.1.456.0'
930930
$mockapiUrl = 'https://ci.appveyor.com/api'
@@ -1383,6 +1383,7 @@ Configuration Example
13831383
$script:mockReadmePath = Join-Path -Path $script:mockSchemaFolder -ChildPath 'readme.md'
13841384
$script:mockOutputFile = Join-Path -Path $script:mockOutputPath -ChildPath "$($script:mockResourceName).md"
13851385
$script:mockSavePath = Join-Path -Path $script:mockModulePath -ChildPath "DscResources\$($script:mockResourceName)\en-US\about_$($script:mockResourceName).help.txt"
1386+
$script:mockOutputSavePath = Join-Path -Path $script:mockOutputPath -ChildPath "about_$($script:mockResourceName).help.txt"
13861387
$script:mockGetContentReadme = '# Description
13871388
13881389
The description of the resource.'
@@ -1455,6 +1456,10 @@ Configuration Example
14551456
$InputObject -eq $script:mockPowerShellHelpOutput -and
14561457
$FilePath -eq $script:mockSavePath
14571458
}
1459+
$script:outFileOutputInputObject_parameterFilter = {
1460+
$InputObject -eq $script:mockPowerShellHelpOutput -and
1461+
$FilePath -eq $script:mockOutputSavePath
1462+
}
14581463
$script:writeWarningDescription_parameterFilter = {
14591464
$Message -eq ($script:localizedData.NoDescriptionFileFoundWarning -f $mockResourceName)
14601465
}
@@ -1465,6 +1470,10 @@ Configuration Example
14651470
$script:newDscResourcePowerShellHelp_parameters = @{
14661471
ModulePath = $script:mockModulePath
14671472
}
1473+
$script:newDscResourcePowerShellHelpOutput_parameters = @{
1474+
ModulePath = $script:mockModulePath
1475+
OutputPath = $script:mockOutputPath
1476+
}
14681477

14691478
Context 'When there is no schemas found in the module folder' {
14701479
BeforeAll {
@@ -1621,7 +1630,7 @@ Configuration Example
16211630
}
16221631
}
16231632

1624-
Context 'When there is one schema found in the module folder and one example using .EXAMPLE' {
1633+
Context 'When there is one schema found in the module folder and one example using .EXAMPLE and the OutputPath is specified' {
16251634
BeforeAll {
16261635
Mock `
16271636
-CommandName Get-ChildItem `
@@ -1654,8 +1663,105 @@ Configuration Example
16541663
-MockWith { $script:mockExampleContent }
16551664

16561665
Mock `
1666+
-CommandName Out-File
1667+
1668+
Mock `
1669+
-CommandName Write-Warning `
1670+
-ParameterFilter $script:writeWarningExample_parameterFilter
1671+
1672+
Mock `
1673+
-CommandName Write-Warning `
1674+
-ParameterFilter $script:writeWarningDescription_parameterFilter
1675+
}
1676+
1677+
It 'Should not throw an exception' {
1678+
{ New-DscResourcePowerShellHelp @script:newDscResourcePowerShellHelpOutput_parameters } | Should -Not -Throw
1679+
}
1680+
1681+
It 'Should produce the correct output' {
1682+
Assert-MockCalled `
16571683
-CommandName Out-File `
1658-
-ParameterFilter $script:outFile_parameterFilter
1684+
-ParameterFilter $script:outFileOutputInputObject_parameterFilter `
1685+
-Exactly -Times 1
1686+
}
1687+
1688+
It 'Should call the expected mocks ' {
1689+
Assert-MockCalled `
1690+
-CommandName Get-ChildItem `
1691+
-ParameterFilter $script:getChildItemSchema_parameterFilter `
1692+
-Exactly -Times 1
1693+
1694+
Assert-MockCalled `
1695+
-CommandName Get-MofSchemaObject `
1696+
-ParameterFilter $script:getMofSchemaObjectSchema_parameterfilter `
1697+
-Exactly -Times 1
1698+
1699+
Assert-MockCalled `
1700+
-CommandName Test-Path `
1701+
-ParameterFilter $script:getTestPathReadme_parameterFilter `
1702+
-Exactly -Times 1
1703+
1704+
Assert-MockCalled `
1705+
-CommandName Get-Content `
1706+
-ParameterFilter $script:getContentReadme_parameterFilter `
1707+
-Exactly -Times 1
1708+
1709+
Assert-MockCalled `
1710+
-CommandName Get-ChildItem `
1711+
-ParameterFilter $script:getChildItemExample_parameterFilter `
1712+
-Exactly -Times 1
1713+
1714+
Assert-MockCalled `
1715+
-CommandName Get-DscResourceHelpExampleContent `
1716+
-ParameterFilter $script:getDscResourceHelpExampleContent_parameterFilter `
1717+
-Exactly -Times 1
1718+
1719+
Assert-MockCalled `
1720+
-CommandName Write-Warning `
1721+
-ParameterFilter $script:writeWarningExample_parameterFilter `
1722+
-Exactly -Times 0
1723+
1724+
Assert-MockCalled `
1725+
-CommandName Write-Warning `
1726+
-ParameterFilter $script:writeWarningDescription_parameterFilter `
1727+
-Exactly -Times 0
1728+
}
1729+
}
1730+
1731+
Context 'When there is one schema found in the module folder and one example using .EXAMPLE and the OutputPath is not specified' {
1732+
BeforeAll {
1733+
Mock `
1734+
-CommandName Get-ChildItem `
1735+
-ParameterFilter $script:getChildItemSchema_parameterFilter `
1736+
-MockWith { $script:mockSchemaFiles }
1737+
1738+
Mock `
1739+
-CommandName Get-MofSchemaObject `
1740+
-ParameterFilter $script:getMofSchemaObjectSchema_parameterfilter `
1741+
-MockWith { $script:mockGetMofSchemaObject }
1742+
1743+
Mock `
1744+
-CommandName Test-Path `
1745+
-ParameterFilter $script:getTestPathReadme_parameterFilter `
1746+
-MockWith { $true }
1747+
1748+
Mock `
1749+
-CommandName Get-Content `
1750+
-ParameterFilter $script:getContentReadme_parameterFilter `
1751+
-MockWith { $script:mockGetContentReadme }
1752+
1753+
Mock `
1754+
-CommandName Get-ChildItem `
1755+
-ParameterFilter $script:getChildItemExample_parameterFilter `
1756+
-MockWith { $script:mockExampleFiles }
1757+
1758+
Mock `
1759+
-CommandName Get-DscResourceHelpExampleContent `
1760+
-ParameterFilter $script:getDscResourceHelpExampleContent_parameterFilter `
1761+
-MockWith { $script:mockExampleContent }
1762+
1763+
Mock `
1764+
-CommandName Out-File
16591765

16601766
Mock `
16611767
-CommandName Write-Warning `
@@ -1693,7 +1799,7 @@ Configuration Example
16931799
-ParameterFilter $script:getTestPathReadme_parameterFilter `
16941800
-Exactly -Times 1
16951801

1696-
Assert-MockCalled `
1802+
Assert-MockCalled `
16971803
-CommandName Get-Content `
16981804
-ParameterFilter $script:getContentReadme_parameterFilter `
16991805
-Exactly -Times 1

0 commit comments

Comments
 (0)