-
Notifications
You must be signed in to change notification settings - Fork 0
/
Option.cs
75 lines (71 loc) · 1.98 KB
/
Option.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
internal abstract class Option {
public string ShortName;
public string LongName;
public string Help;
public bool HasLongName;
public bool Required;
public Option(string shortName, string longName = "", string help = "", bool required = true) {
this.ShortName = shortName;
this.LongName = longName;
this.Help = help;
this.HasLongName = longName != "";
this.Required = required;
}
public abstract string FormattedHelp();
}
internal class OptionArg : Option{
string MetaVar;
public bool RequiredVArgs {get;}
public OptionArg (
string shortName,
string metaVar,
string longName = "",
string help = "",
bool required = true,
bool requiredVArgs = false
) : base(shortName, longName, help) {
this.Required = required;
this.RequiredVArgs = requiredVArgs;
this.MetaVar = metaVar;
}
public override string FormattedHelp()
{
string s = $"{this.ShortName}";
if(this.LongName != "")
s += $", {this.LongName}";
s += $" {MetaVar}";
if(this.Help != "")
s += $"\t{this.Help}";
return s;
}
}
internal class OptionFlag : Option {
public OptionFlag (
string shortName,
string longName = "",
string help = ""
) : base(shortName, longName, help, false) {}
public override string FormattedHelp() {
string s = $"{this.ShortName}";
if(this.LongName != "")
s += $", {this.LongName}";
if(this.Help != "")
s += $"\t{this.Help}";
return s;
}
}
/*
internal class PositionArgs : Option {
string MetaVar;
public PositionArgs(string metaVar, string help) : base("", "", help, true) {
this.MetaVar = metaVar;
}
public override string FormattedHelp()
{
string s = $" {MetaVar}";
if(this.Help != "")
s += $"\t{this.Help}";
return s;
}
}
*/