-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
83 lines (71 loc) · 2.15 KB
/
Program.cs
File metadata and controls
83 lines (71 loc) · 2.15 KB
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
using System;
using System.IO;
using System.Linq;
namespace generator
{
public class Program
{
private const string Version = "v1.0.3-dev";
public static void Main(string[] args)
{
if (!args.Any())
{
DeployDefaultConfig();
return;
}
if (IsVersionCall(args))
{
Log.Write("Version: " + Version);
return;
}
if (!File.Exists(args[0]))
{
Log.Write("File not found: '" + args[0] + "'");
return;
}
RunGenerator(args[0]);
}
private static void DeployDefaultConfig()
{
var generator = new DefaultConfigGenerator();
generator.CreateDefaultConfig();
}
private static bool IsVersionCall(string[] args)
{
return args.Any(a =>
{
var lower = a.ToLowerInvariant();
return lower == "-v" || lower == "--version";
});
}
private static void RunGenerator(string configFile)
{
Log.Write("Loading configuration from '" + configFile + "'...");
var config = ReadConfig(configFile);
Log.Write("Validating...");
var validator = new ConfigValidator();
validator.Validate(config);
if (!validator.IsValid) return;
Log.Write("Running generators...");
var gen = new Generator(config);
gen.Generate();
Log.Write("");
Log.Write("Done!");
Log.Write("See the 'Readme.md' of your new project for build and test instructions.");
Log.Write("");
}
private static GeneratorConfig ReadConfig(string configFile)
{
try
{
return new ConfigLoader().TryParse(configFile);
}
catch (Exception ex)
{
Log.Write("Error while reading config file:");
Log.Write(ex.ToString());
return null;
}
}
}
}