Skip to content

Commit 4e64327

Browse files
yishengjin1413vors
authored andcommitted
support use fulltypename (#275)
1 parent fe8a524 commit 4e64327

File tree

4 files changed

+156
-22
lines changed

4 files changed

+156
-22
lines changed

docs/New-MarkdownHelp.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ Creates help in markdown format.
1414
### FromModule
1515
```
1616
New-MarkdownHelp -Module <String[]> [-Force] [-AlphabeticParamsOrder] [-Metadata <Hashtable>]
17-
-OutputFolder <String> [-NoMetadata] [-Encoding <Encoding>] [-WithModulePage] [-Locale <String>]
18-
[-HelpVersion <String>] [-FwLink <String>] [<CommonParameters>]
17+
-OutputFolder <String> [-NoMetadata] [-UseFullTypeName] [-Encoding <Encoding>] [-WithModulePage]
18+
[-Locale <String>] [-HelpVersion <String>] [-FwLink <String>] [<CommonParameters>]
1919
```
2020

2121
### FromCommand
2222
```
2323
New-MarkdownHelp -Command <String[]> [-Force] [-AlphabeticParamsOrder] [-Metadata <Hashtable>]
24-
[-OnlineVersionUrl <String>] -OutputFolder <String> [-NoMetadata] [-Encoding <Encoding>] [<CommonParameters>]
24+
[-OnlineVersionUrl <String>] -OutputFolder <String> [-NoMetadata] [-UseFullTypeName] [-Encoding <Encoding>]
25+
[<CommonParameters>]
2526
```
2627

2728
### FromMaml
2829
```
2930
New-MarkdownHelp -MamlFile <String[]> [-ConvertNotesToList] [-ConvertDoubleDashLists] [-Force]
30-
[-AlphabeticParamsOrder] [-Metadata <Hashtable>] -OutputFolder <String> [-NoMetadata] [-Encoding <Encoding>]
31-
[-WithModulePage] [-Locale <String>] [-HelpVersion <String>] [-FwLink <String>] [-ModuleName <String>]
32-
[-ModuleGuid <String>] [<CommonParameters>]
31+
[-AlphabeticParamsOrder] [-Metadata <Hashtable>] -OutputFolder <String> [-NoMetadata] [-UseFullTypeName]
32+
[-Encoding <Encoding>] [-WithModulePage] [-Locale <String>] [-HelpVersion <String>] [-FwLink <String>]
33+
[-ModuleName <String>] [-ModuleGuid <String>] [<CommonParameters>]
3334
```
3435

3536
## DESCRIPTION
@@ -426,6 +427,21 @@ Accept pipeline input: False
426427
Accept wildcard characters: False
427428
```
428429
430+
### -UseFullTypeName
431+
Indicates that the target document will use a full type name instead of a short name for parameters.
432+
433+
```yaml
434+
Type: SwitchParameter
435+
Parameter Sets: (All)
436+
Aliases:
437+
438+
Required: False
439+
Position: Named
440+
Default value: None
441+
Accept pipeline input: False
442+
Accept wildcard characters: False
443+
```
444+
429445
### CommonParameters
430446
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
431447

docs/Update-MarkdownHelp.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Update PlatyPS markdown help files.
1313

1414
```
1515
Update-MarkdownHelp [-Path] <String[]> [[-Encoding] <Encoding>] [[-LogPath] <String>] [-LogAppend]
16-
[-AlphabeticParamsOrder] [<CommonParameters>]
16+
[-AlphabeticParamsOrder] [-UseFullTypeName] [<CommonParameters>]
1717
```
1818

1919
## DESCRIPTION
@@ -157,6 +157,21 @@ Accept pipeline input: False
157157
Accept wildcard characters: False
158158
```
159159
160+
### -UseFullTypeName
161+
Indicates that the target document will use a full type name instead of a short name for parameters.
162+
163+
```yaml
164+
Type: SwitchParameter
165+
Parameter Sets: (All)
166+
Aliases:
167+
168+
Required: False
169+
Position: Named
170+
Default value: None
171+
Accept pipeline input: False
172+
Accept wildcard characters: False
173+
```
174+
160175
### CommonParameters
161176
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
162177

src/platyPS/platyPS.psm1

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ function New-MarkdownHelp
7474
[string]$OutputFolder,
7575

7676
[switch]$NoMetadata,
77+
78+
[switch]$UseFullTypeName,
7779

7880
[System.Text.Encoding]$Encoding = $script:UTF8_NO_BOM,
7981

@@ -227,7 +229,7 @@ function New-MarkdownHelp
227229
throw "Command $_ not found in the session."
228230
}
229231

230-
GetMamlObject -Cmdlet $_ | processMamlObjectToFile
232+
GetMamlObject -Cmdlet $_ -UseFullTypeName:$UseFullTypeName | processMamlObjectToFile
231233
}
232234
}
233235
else
@@ -249,7 +251,7 @@ function New-MarkdownHelp
249251
throw "Module $_ is not imported in the session. Run 'Import-Module $_'."
250252
}
251253

252-
GetMamlObject -Module $_ | processMamlObjectToFile
254+
GetMamlObject -Module $_ -UseFullTypeName:$UseFullTypeName | processMamlObjectToFile
253255

254256
$ModuleName = $_
255257
$ModuleGuid = (Get-Module $ModuleName).Guid
@@ -342,7 +344,8 @@ function Update-MarkdownHelp
342344

343345
[string]$LogPath,
344346
[switch]$LogAppend,
345-
[switch]$AlphabeticParamsOrder
347+
[switch]$AlphabeticParamsOrder,
348+
[switch]$UseFullTypeName
346349
)
347350

348351
begin
@@ -408,7 +411,7 @@ function Update-MarkdownHelp
408411
# update the help file entry in the metadata
409412
$metadata = Get-MarkdownMetadata $filePath
410413
$metadata["external help file"] = GetHelpFileName $command
411-
$reflectionModel = GetMamlObject -Cmdlet $name
414+
$reflectionModel = GetMamlObject -Cmdlet $name -UseFullTypeName:$UseFullTypeName
412415

413416
$merger = New-Object Markdown.MAML.Transformer.MamlModelMerger -ArgumentList $infoCallback
414417
$newModel = $merger.Merge($reflectionModel, $oldModel)
@@ -1926,7 +1929,8 @@ function GetMamlObject
19261929
[parameter(parametersetname="Maml")]
19271930
[switch] $ConvertNotesToList,
19281931
[parameter(parametersetname="Maml")]
1929-
[switch] $ConvertDoubleDashLists
1932+
[switch] $ConvertDoubleDashLists,
1933+
[switch] $UseFullTypeName
19301934
)
19311935

19321936
function CommandHasAutogeneratedSynopsis
@@ -1941,7 +1945,7 @@ function GetMamlObject
19411945
Write-Verbose ("Processing: " + $Cmdlet)
19421946
$Help = Get-Help $Cmdlet
19431947
$Command = Get-Command $Cmdlet
1944-
return ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UsePlaceholderForSynopsis:(CommandHasAutogeneratedSynopsis $Help)
1948+
return ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UsePlaceholderForSynopsis:(CommandHasAutogeneratedSynopsis $Help) -UseFullTypeName:$UseFullTypeName
19451949
}
19461950
elseif ($Module)
19471951
{
@@ -1953,7 +1957,7 @@ function GetMamlObject
19531957
Write-Verbose ("`tProcessing: " + $Command.Name)
19541958
$Help = Get-Help $Command.Name
19551959
# yeild
1956-
ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UsePlaceholderForSynopsis:(CommandHasAutogeneratedSynopsis $Help)
1960+
ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UsePlaceholderForSynopsis:(CommandHasAutogeneratedSynopsis $Help) -UseFullTypeName:$UseFullTypeName
19571961
}
19581962
}
19591963
else # Maml
@@ -1974,7 +1978,7 @@ function GetMamlObject
19741978
}
19751979

19761980
# yeild
1977-
ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UseHelpForParametersMetadata
1981+
ConvertPsObjectsToMamlModel -Command $Command -Help $Help -UseHelpForParametersMetadata -UseFullTypeName:$UseFullTypeName
19781982
}
19791983
}
19801984
}
@@ -2036,7 +2040,8 @@ function ConvertPsObjectsToMamlModel
20362040
[Parameter(Mandatory=$true)]
20372041
[object]$Help,
20382042
[switch]$UseHelpForParametersMetadata,
2039-
[switch]$UsePlaceholderForSynopsis
2043+
[switch]$UsePlaceholderForSynopsis,
2044+
[switch]$UseFullTypeName
20402045
)
20412046

20422047
function isCommonParameterName
@@ -2239,12 +2244,18 @@ function ConvertPsObjectsToMamlModel
22392244
}
22402245

22412246
$ParameterObject = New-Object -TypeName Markdown.MAML.Model.MAML.MamlParameter
2242-
$ParameterType = $Parameter.ParameterType
2243-
$ParameterObject.Type = getTypeString -typeObject $ParameterType
22442247
$ParameterObject.Name = $Parameter.Name
22452248
$ParameterObject.Required = $Parameter.IsMandatory
22462249
$ParameterObject.PipelineInput = getPipelineValue $Parameter
2247-
2250+
$ParameterType = $Parameter.ParameterType
2251+
$ParameterObject.Type = if ($UseFullTypeName)
2252+
{
2253+
$ParameterType.FullName
2254+
}
2255+
else
2256+
{
2257+
getTypeString -typeObject $ParameterType
2258+
}
22482259
$ParameterObject.ValueRequired = -not ($Parameter.Type -eq "SwitchParameter") # thisDefinition is a heuristic
22492260

22502261
foreach($Alias in $Parameter.Aliases)

test/Pester/PlatyPs.Tests.ps1

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ $outFolder = "$root\out"
77
Import-Module $outFolder\platyPS -Force
88

99
Describe 'New-MarkdownHelp' {
10+
function normalizeEnds([string]$text)
11+
{
12+
$text -replace "`r`n?|`n", "`r`n"
13+
}
1014

1115
Context 'errors' {
1216
It 'throw when cannot find module' {
@@ -122,16 +126,18 @@ Describe 'New-MarkdownHelp' {
122126
}
123127

124128
It 'uses alphabetic order when specified' {
125-
$files = New-MarkdownHelp -Command Get-Alpha -OutputFolder TestDrive:\alpha -Force -AlphabeticParamsOrder
126-
($files | Measure-Object).Count | Should Be 1
127-
Get-Content $files | Where-Object {$_.StartsWith('### -')} | Out-String | Should Be @'
129+
130+
$expectedOrder = normalizeEnds @'
128131
### -AAA
129132
### -BBB
130133
### -CCC
131134
### -Confirm
132135
### -WhatIf
133136
134137
'@
138+
$files = New-MarkdownHelp -Command Get-Alpha -OutputFolder TestDrive:\alpha -Force -AlphabeticParamsOrder
139+
($files | Measure-Object).Count | Should Be 1
140+
Get-Content $files | Where-Object {$_.StartsWith('### -')} | Out-String | Should Be $expectedOrder
135141
}
136142
}
137143

@@ -379,6 +385,54 @@ Describe 'New-MarkdownHelp' {
379385

380386
}
381387
}
388+
389+
Context 'Full Type Name' {
390+
function global:Get-Alpha
391+
{
392+
param(
393+
[Switch]
394+
[Parameter(Position=1)]
395+
$WhatIf,
396+
[string]
397+
[Parameter(Position=2)]
398+
$CCC
399+
)
400+
}
401+
402+
It 'use full type name when specified' {
403+
$expectedParameters = normalizeEnds @'
404+
Type: System.String
405+
Type: System.Management.Automation.SwitchParameter
406+
407+
'@
408+
$expectedSyntax = normalizeEnds @'
409+
Get-Alpha [[-WhatIf] <System.Management.Automation.SwitchParameter>] [[-CCC] <System.String>]
410+
411+
'@
412+
413+
$files = New-MarkdownHelp -Command Get-Alpha -OutputFolder TestDrive:\alpha -Force -AlphabeticParamsOrder -UseFullTypeName
414+
($files | Measure-Object).Count | Should Be 1
415+
Get-Content $files | Where-Object {$_.StartsWith('Type: ')} | Out-String | Should Be $expectedParameters
416+
Get-Content $files | Where-Object {$_.StartsWith('Get-Alpha')} | Out-String | Should Be $expectedSyntax
417+
}
418+
419+
It 'not use full type name when specified' {
420+
$expectedParameters = normalizeEnds @'
421+
Type: String
422+
Type: SwitchParameter
423+
424+
'@
425+
$expectedSyntax = normalizeEnds @'
426+
Get-Alpha [-WhatIf] [[-CCC] <String>]
427+
428+
'@
429+
430+
$files = New-MarkdownHelp -Command Get-Alpha -OutputFolder TestDrive:\alpha -Force -AlphabeticParamsOrder
431+
($files | Measure-Object).Count | Should Be 1
432+
Get-Content $files | Where-Object {$_.StartsWith('Type: ')} | Out-String | Should Be $expectedParameters
433+
Get-Content $files | Where-Object {$_.StartsWith('Get-Alpha')} | Out-String | Should Be $expectedSyntax
434+
}
435+
}
382436
}
383437

384438

@@ -807,6 +861,44 @@ It has mutlilines. And hyper (http://link.com).
807861
Update-MarkdownHelp -Path $outputFolder
808862
(Get-Content (Join-Path $outputOriginal Add-Computer.md)) | Should Be (Get-Content (Join-Path $outputUpdated Add-Computer.md))
809863
}
864+
865+
It 'parameter type should not be fullname' {
866+
$expectedParameters = normalizeEnds @'
867+
Type: String
868+
Type: String
869+
870+
'@
871+
$expectedSyntax = normalizeEnds @'
872+
Get-MyCoolStuff [[-Foo] <String>] [[-Bar] <String>] [<CommonParameters>]
873+
874+
'@
875+
$v2md | Get-Content | Where-Object {$_.StartsWith('Type: ')} | Out-String | Should Be $expectedParameters
876+
$v2md | Get-Content | Where-Object {$_.StartsWith('Get-MyCoolStuff')} | Out-String | Should Be $expectedSyntax
877+
}
878+
879+
$v3md = Update-MarkdownHelp $v2md -Verbose -AlphabeticParamsOrder -UseFullTypeName
880+
881+
$v3markdown = $v3md | Get-Content
882+
883+
It 'parameter type should be fullname' {
884+
$expectedParameters = normalizeEnds @'
885+
Type: System.String
886+
Type: System.String
887+
888+
'@
889+
$expectedSyntax = normalizeEnds @'
890+
Get-MyCoolStuff [[-Foo] <System.String>] [[-Bar] <System.String>] [<CommonParameters>]
891+
892+
'@
893+
$v3markdown | Where-Object {$_.StartsWith('Type: ')} | Out-String | Should Be $expectedParameters
894+
$v3markdown | Where-Object {$_.StartsWith('Get-MyCoolStuff')} | Out-String | Should Be $expectedSyntax
895+
}
896+
897+
It 'all the other part should be the same except line with parameters' {
898+
$expectedContent = $v2md | Get-Content | Select-String -pattern "Type: |Get-MyCoolStuff" -notmatch | Out-String
899+
$v3markdown | Select-String -pattern "Type: |Get-MyCoolStuff" -notmatch | Out-String | Should Be $expectedContent
900+
901+
}
810902
}
811903

812904
Describe 'Update Markdown Help' {

0 commit comments

Comments
 (0)