Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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
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
Loading