forked from MihaMarkic/Cake.Docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
args-parser-2.linq
106 lines (102 loc) · 2.05 KB
/
args-parser-2.linq
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<Query Kind="Statements" />
string file = @"D:\GitProjects\Righthand\Cake\Cake.Docker\src\Cake.Docker\Compose\Up\args.txt";
string[] lines = File.ReadAllLines(file);
Regex regex = new Regex(
"--(?<Argument>[a-z0-9,\\-]+)(?:\\s(?<Type>\\w+))?\\s+(?<Info>.+" +
")",
RegexOptions.IgnoreCase
| RegexOptions.Multiline
| RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
Dictionary<string, List<string>> data = new Dictionary<string, List<string>>();
List<string> current = null;
foreach (string line in lines.Where(l =>!string.IsNullOrEmpty(l)).Select(l => l.TrimStart()))
{
if (line.StartsWith("-"))
{
current = new List<string>();
data.Add(line, current);
}
else
{
current.Add(line.Trim());
}
}
foreach (var pair in data)
{
string line = pair.Key;
var match = regex.Match(line);
if (!match.Success)
{
("FAILED to match " + line).Dump();
}
else
{
string rawName = match.Groups["Argument"].Value;
string type = match.Groups["Type"].Value;
string info = match.Groups["Info"].Value;
string name = "";
bool upperCase = true;
foreach (char c in rawName)
{
if (upperCase)
{
name += char.ToUpper(c);
upperCase = false;
}
else
{
if (c == '-')
{
upperCase = true;
}
else
{
name += c;
}
}
}
List<string> comment = new List<string>();
comment.Add(info);
comment.AddRange(pair.Value.Select(l => $"\t{l}"));
"/// <summary>".Dump();
foreach (string commentLine in comment)
{
("/// " + commentLine
.Replace("<", "<")
.Replace(">", ">"))
.Dump();
}
"/// </summary>".Dump();
string netType;
switch (type)
{
case "duration":
netType = "TimeSpan?";
break;
case "int?":
case "int":
case "uint":
netType = "int";
break;
case "value":
if (info.EndsWith("[])"))
{
netType = "string[]";
}
else
{
netType = "string";
}
break;
case "string":
netType = "string";
break;
default:
netType = "bool";
break;
}
$"public {netType} {name} {{ get; set; }}".Dump();
}
}