Skip to content

Ensure all the metadata is added to CommandHelp #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Common/YamlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions src/MarkdownReader/CommandHelpMarkdownReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Transform/TransformBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/Pester/ExportMamlCommandHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
12 changes: 12 additions & 0 deletions test/Pester/ImportMarkdownCommandHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down