1 ///Load JSON config file
2 module util.config;
3 import util.inform;
4 
5 abstract class BuildSpecification
6 {
7     ///User defined named of thing from config file
8     string name;
9     ///Exact string as if executed on shell
10     string exactCommand;
11     string[] programAndArgs;
12     this(string sName, string sShellString, string[] args = null)
13     {
14         name = sName;
15         exactCommand = sShellString;
16         programAndArgs = args;
17     }
18 }
19 ///Build something on the shell, not required to do anything in particular
20 class RawBuild : BuildSpecification
21 {
22     this()
23     {
24         super(null, null, null);
25     }
26 
27     this(string sName, string sShell)
28     {
29         super(sName, sShell, null);
30     }
31 }
32 
33 struct ConfigResult
34 {
35     const(BuildSpecification) getBuildByString(string name) const
36     {
37         import std.algorithm : find;
38         const res = rawBuilds.find!(x => x.name == name);
39 
40         if (!res.length)
41             throw new Exception("Could not find build of name: " ~ name);
42         return res[0];
43     }
44 
45     RawBuild[] rawBuilds;
46 }
47 
48 auto loadConfig(string name)
49 {
50     import asdf;
51     import std.file;
52 
53     const confString = readText(name);
54 
55     try
56     {
57         const output = confString.deserialize!ConfigResult;
58         return output;
59     }
60     catch (Exception e)
61     {
62         import std.format;
63 
64         inform("Error Parsing config file");
65 
66         alert(e.msg);
67     }
68     assert(0);
69 }