From c9afbc296d39d3d57b46bf44e2f538021bee2bf3 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 23 Jul 2025 19:31:14 +0000 Subject: [PATCH 1/3] Ensure all the metadata is added to CommandHelp --- src/MarkdownReader/CommandHelpMarkdownReader.cs | 7 +++++++ src/Transform/TransformBase.cs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/MarkdownReader/CommandHelpMarkdownReader.cs b/src/MarkdownReader/CommandHelpMarkdownReader.cs index fecd88b1..5d85e244 100644 --- a/src/MarkdownReader/CommandHelpMarkdownReader.cs +++ b/src/MarkdownReader/CommandHelpMarkdownReader.cs @@ -224,6 +224,13 @@ internal static CommandHelp GetCommandHelpFromMarkdown(ParsedMarkdownContent mar } commandHelp.Metadata = metadata; + commandHelp.ExternalHelpFile = metadata["external help file"] as string ?? string.Empty; + commandHelp.SchemaVersion = metadata["PlatyPS schema version"] as string ?? string.Empty; + commandHelp.OnlineVersionUrl = metadata["HelpUri"] as string ?? string.Empty; + + string? moduleGuid = metadata["ModuleGuid"] as string; + commandHelp.ModuleGuid = moduleGuid is not null ? new Guid(moduleGuid) : null; + commandHelp.HasCmdletBinding = GetCmdletBindingState(markdownContent, out var cmdletBindingDiagnostics); if (cmdletBindingDiagnostics is not null) { diff --git a/src/Transform/TransformBase.cs b/src/Transform/TransformBase.cs index 42ec630d..e1fa9b78 100644 --- a/src/Transform/TransformBase.cs +++ b/src/Transform/TransformBase.cs @@ -54,11 +54,11 @@ protected CommandHelp ConvertCmdletInfo(CommandInfo? commandInfo) addDefaultStrings = true; } - CommandHelp cmdHelp = new(commandInfo.Name, commandInfo.ModuleName, Settings.Locale); cmdHelp.Metadata = MetadataUtils.GetCommandHelpBaseMetadataFromCommandInfo(commandInfo); cmdHelp.ExternalHelpFile = cmdHelp.Metadata["external help file"].ToString() ?? string.Empty; - cmdHelp.OnlineVersionUrl = Settings.OnlineVersionUrl; + cmdHelp.OnlineVersionUrl = Settings.OnlineVersionUrl ?? cmdHelp.Metadata["HelpUri"] as string; + cmdHelp.SchemaVersion = cmdHelp.Metadata["PlatyPS schema version"] as string ?? string.Empty; cmdHelp.Synopsis = GetSynopsis(helpItem, addDefaultStrings); cmdHelp.AddSyntaxItemRange(GetSyntaxItem(commandInfo, helpItem)); cmdHelp.Description = GetDescription(helpItem, addDefaultStrings).Trim(); From d20ed9c3e89c0a83297bb91bcf69b4ec4b0de2d0 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 23 Jul 2025 13:36:09 -0700 Subject: [PATCH 2/3] Add test --- test/Pester/ImportMarkdownCommandHelp.Tests.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/Pester/ImportMarkdownCommandHelp.Tests.ps1 b/test/Pester/ImportMarkdownCommandHelp.Tests.ps1 index 288828af..070404a0 100644 --- a/test/Pester/ImportMarkdownCommandHelp.Tests.ps1 +++ b/test/Pester/ImportMarkdownCommandHelp.Tests.ps1 @@ -65,6 +65,18 @@ Describe 'Import-MarkdownCommandHelp Tests' { It 'Should be able to read multiline metadata' { $md.Metadata['foo'] | Should -Be "bar" } + + It 'Should be able to set all metadata properties' { + $m = Import-MarkdownCommandHelp -Path "$assetdir/get-date.md" + $m.ExternalHelpFile | Should -Be "Microsoft.PowerShell.Commands.Utility.dll-Help.xml" + $m.Locale | Should -Be "en-US" + $m.SchemaVersion | Should -Be "2024-05-01" + $m.OnlineVersionUrl | Should -Be "https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-date?view=powershell-7.4&WT.mc_id=ps-gethelp" + $m.ModuleGuid | Should -BeNullOrEmpty + + $maml = $m | Export-MamlCommandHelp -OutputFolder $TestDrive -Force -Verbose + $maml.Name | Should -Be 'Microsoft.PowerShell.Commands.Utility.dll-Help.xml' + } } Context "Validate Aliases" { From 8d6e0ce9f868363e34772a96c2b691da035f079a Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Wed, 23 Jul 2025 21:47:54 +0000 Subject: [PATCH 3/3] Fix Yaml import and export tests --- src/Common/YamlUtils.cs | 4 ++++ test/Pester/ExportMamlCommandHelp.Tests.ps1 | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Common/YamlUtils.cs b/src/Common/YamlUtils.cs index f0e17f0d..3e7a0bda 100644 --- a/src/Common/YamlUtils.cs +++ b/src/Common/YamlUtils.cs @@ -190,6 +190,10 @@ internal static CommandHelp ConvertDictionaryToCommandHelp(OrderedDictionary? di { help.Metadata = GetMetadataFromDictionary(metadata); help.Diagnostics.TryAddDiagnostic(DiagnosticMessageSource.General, "Found Metadata", DiagnosticSeverity.Information, "yaml metadata", -1); + + help.ExternalHelpFile = metadata["external help file"] as string ?? string.Empty; + help.SchemaVersion = metadata["PlatyPS schema version"] as string ?? string.Empty; + help.OnlineVersionUrl = metadata["HelpUri"] as string ?? string.Empty; } if (dictionary["synopsis"] is string synopsis) diff --git a/test/Pester/ExportMamlCommandHelp.Tests.ps1 b/test/Pester/ExportMamlCommandHelp.Tests.ps1 index 06a1c44a..32d1ffb5 100644 --- a/test/Pester/ExportMamlCommandHelp.Tests.ps1 +++ b/test/Pester/ExportMamlCommandHelp.Tests.ps1 @@ -7,8 +7,8 @@ Describe "Export-MamlCommandHelp tests" { $markdownFiles = 'get-date.md', 'Import-Module.md', 'Invoke-Command.md', 'Out-Null.md' $chObjects = $markdownFiles | Foreach-Object { Import-MarkdownCommandHelp (Join-Path $assetDir $_) } $outputDirectory = Join-Path $TESTDRIVE MamlBase - $f1 = "$outputDirectory/Microsoft.PowerShell.Core/Microsoft.PowerShell.Core-Help.xml" - $f2 = "$outputDirectory/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Utility-Help.xml" + $f1 = "$outputDirectory/Microsoft.PowerShell.Core/System.Management.Automation.dll-Help.xml" + $f2 = "$outputDirectory/Microsoft.PowerShell.Utility/Microsoft.PowerShell.Commands.Utility.dll-Help.xml" } Context "Basic Operations" {