Improve XmlDoc output (#1503)

* Add command description and examples in XML Output

Closes #1115
This commit is contained in:
Yennefer
2024-03-29 20:30:59 +01:00
committed by GitHub
parent 43f9ae92ad
commit 1a3249cdae
11 changed files with 87 additions and 0 deletions

View File

@ -84,6 +84,13 @@ internal sealed class XmlDocCommand : Command<XmlDocCommand.Settings>
node.SetNullableAttribute("Settings", command.SettingsType?.FullName);
if (!string.IsNullOrWhiteSpace(command.Description))
{
var descriptionNode = doc.CreateElement("Description");
descriptionNode.InnerText = command.Description;
node.AppendChild(descriptionNode);
}
// Parameters
if (command.Parameters.Count > 0)
{
@ -103,6 +110,27 @@ internal sealed class XmlDocCommand : Command<XmlDocCommand.Settings>
node.AppendChild(CreateCommandNode(doc, childCommand));
}
// Examples
if (command.Examples.Count > 0)
{
var exampleRootNode = doc.CreateElement("Examples");
foreach (var example in command.Examples.SelectMany(static x => x))
{
var exampleNode = CreateExampleNode(doc, example);
exampleRootNode.AppendChild(exampleNode);
}
node.AppendChild(exampleRootNode);
}
return node;
}
private static XmlNode CreateExampleNode(XmlDocument document, string example)
{
var node = document.CreateElement("Example");
node.SetAttribute("commandLine", example);
return node;
}