-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathTopLevelUsageWriter.cs
35 lines (29 loc) · 1.08 KB
/
TopLevelUsageWriter.cs
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
using Ookii.CommandLine;
using Ookii.CommandLine.Commands;
namespace TopLevelArguments;
// Custom UsageWriter used for the top-level arguments.
internal class TopLevelUsageWriter : UsageWriter
{
private readonly CommandManager _manager;
public TopLevelUsageWriter(CommandManager manager)
{
_manager = manager;
}
// Show the positional arguments last to indicate arguments after --command must be command
// arguments.
protected override IEnumerable<CommandLineArgument> GetArgumentsInUsageOrder()
=> Parser.Arguments
.Where(a => a.Position == null)
.Concat(Parser.Arguments.Where(a => a.Position != null));
// Indicate command arguments can follow the --command argument.
protected override void WriteUsageSyntaxSuffix()
{
Writer.Write(" [command arguments]");
}
// Write the command list at the end of the usage.
protected override void WriteArgumentDescriptions()
{
base.WriteArgumentDescriptions();
_manager.WriteUsage();
}
}