-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListDocsTopicsCommand.cs
More file actions
41 lines (35 loc) · 1.25 KB
/
Copy pathListDocsTopicsCommand.cs
File metadata and controls
41 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.CommandLine;
using System.CommandLine.Invocation;
namespace HelpLine.Docs;
/// <summary>
/// Lists available documentation topics.
/// </summary>
public sealed class ListDocsTopicsCommand : Command
{
public ListDocsTopicsCommand(DocsTopicCatalog catalog)
: base("list", "Lists available documentation topics.")
{
Action = new ListAction(catalog);
}
internal static void WriteTopicList(TextWriter output, DocsTopicCatalog catalog)
{
output.WriteLine("Available documentation topics:");
output.WriteLine();
foreach (var topic in catalog.Topics)
{
var indent = new string(' ', 2 + Math.Max(0, (topic.Level - 1) * 2));
output.WriteLine($"{indent}{topic.ShortName}");
}
output.WriteLine();
output.WriteLine("Usage example:");
output.WriteLine($" {RootCommand.ExecutableName} docs --topic <topic-name>");
}
private sealed class ListAction(DocsTopicCatalog catalog) : SynchronousCommandLineAction
{
public override int Invoke(ParseResult parseResult)
{
WriteTopicList(parseResult.InvocationConfiguration.Output, catalog);
return 0;
}
}
}