-
Notifications
You must be signed in to change notification settings - Fork 7
/
CustomStringProvider.cs
32 lines (28 loc) · 1.31 KB
/
CustomStringProvider.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
using Ookii.CommandLine;
using Ookii.CommandLine.Validation;
namespace CustomUsage;
// A custom string provider can be used to customize many of the strings used by Ookii.CommandLine,
// including error messages and automatic argument names. Here, it is used to customize the help
// argument short name and the usage help for the ValidateRangeAttribute.
internal class CustomStringProvider : LocalizedStringProvider
{
// By overriding this, the "--help" argument no longer uses "-?" as its short name. Normally, it
// would also have an alias "-h", but since the short name is already "-h" the alias is no
// longer used.
public override char AutomaticHelpShortName() => 'h';
// Customize the help for the ValidateRangeAttribute.
public override string ValidateRangeUsageHelp(ValidateRangeAttribute attribute)
{
// Minimum and maximum are both optional (though one of them must be set), so take that
// into account (even though this sample doesn't use that).
if (attribute.Minimum == null)
{
return $"[max: {attribute.Maximum}";
}
else if (attribute.Maximum == null)
{
return $"[min: {attribute.Minimum}";
}
return $"[range: {attribute.Minimum}-{attribute.Maximum}]";
}
}