forked from MihaMarkic/Cake.Docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs-parser-3.linq
97 lines (91 loc) · 1.98 KB
/
args-parser-3.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
<Query Kind="Program" />
void Main()
{
string path = @"Exec";
string file = $@"D:\GitProjects\Righthand\Cake\Cake.Docker\src\Cake.Docker\{path}\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
// );
string[] fileParts = path.Split('\\');
string className = string.Join("", fileParts);
"namespace Cake.Docker".Dump();
"{".Dump();
"/// <summary>".Dump();
"/// Settings for docker swarm init.".Dump();
"/// </summary>".Dump();
$"public sealed class Docker{className}Settings : AutoToolSettings".Dump();
"{".Dump();
foreach (string line in lines)
{
string[] args = line.Split('\t');
//$"{args[0]}|{args[1]}|{args[2]}".Dump();
string[] commands = args[0].Split(',').Select(s => s.Trim()).ToArray();
string argument = args[1].Trim();
string description = args[2];
string name = FormatName(commands[0]);
string type = GetType(argument);
"/// <summary>".Dump();
$"/// {args[0]}".Dump();
if (!string.IsNullOrEmpty(argument))
{
$"/// default: {argument}".Dump();
}
$"/// {description}".Dump();
"/// </summary>".Dump();
$"public {type} {name} {{ get; set; }}".Dump();
}
"}".Dump();
"}".Dump();
}
string FormatName(string argument)
{
string name = "";
bool upperCase = true;
foreach (char c in argument.TrimStart('-'))
{
if (upperCase)
{
name += char.ToUpper(c);
upperCase = false;
}
else
{
if (c == '-')
{
upperCase = true;
}
else
{
name += c;
}
}
}
return name;
}
string GetType(string defaultValue)
{
string netType;
if (string.IsNullOrEmpty(defaultValue))
{
netType = "string";
}
else if (int.TryParse(defaultValue, out int _))
{
netType = "int?";
}
else if (bool.TryParse(defaultValue, out bool _))
{
netType = "bool?";
}
else
{
netType = "string";
}
return netType;
}