-
Notifications
You must be signed in to change notification settings - Fork 7
/
CommandUsageWriter.cs
41 lines (36 loc) · 1.41 KB
/
CommandUsageWriter.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
36
37
38
39
40
41
using Ookii.CommandLine;
namespace TopLevelArguments;
// Custom usage writer used for commands.
class CommandUsageWriter : UsageWriter
{
// This lets us exclude the command usage syntax when appending command usage with the
// TopLevelUsageWriter, and include it when we're running a command and may need to show usage
// for that.
public bool IncludeCommandUsageSyntax { get; set; }
// Indicate there are global arguments in the command usage syntax.
protected override void WriteUsageSyntaxPrefix()
{
WriteColor(UsagePrefixColor);
Write("Usage: ");
ResetColor();
Write(' ');
Write(ExecutableName);
Writer.Write(" [global arguments]");
if (CommandName != null)
{
Write(' ');
Write(CommandName);
}
}
// Omit the usage syntax when writing the command list after the top-level usage help.
protected override void WriteCommandListUsageSyntax()
{
if (IncludeCommandUsageSyntax)
{
base.WriteCommandListUsageSyntax();
}
}
// Also include the global arguments in the help instruction.
protected override void WriteCommandHelpInstruction(string name, string argumentNamePrefix, string argumentName)
=> base.WriteCommandHelpInstruction(name + " [global arguments]", argumentNamePrefix, argumentName);
}