1 /**
2 Copyright 2018 Mark Fisher
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in 
6 the Software without restriction, including without limitation the rights to 
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 
8 of the Software, and to permit persons to whom the Software is furnished to do 
9 so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all 
12 copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
20 SOFTWARE.
21 **/
22 module dxx.gui;
23 
24 private import aermicioi.aedi;
25 
26 private import std.getopt;
27 private import std.conv;
28 private import std.experimental.logger;
29 private import std.meta;
30 
31 private import dxx.util;
32 private import dxx.app;
33 private import dxx.tools;
34 
35 // Compile-time config
36 enum ToolConfig = DXXConfig ~ IniConfig!("tool.ini");
37 
38 mixin __Text!(ToolConfig.tools.lang);
39 
40 @component
41 class ToolsModule : RuntimeModule {
42     void registerTool(alias Cmd : string,T : Tool)(DefaultInjector injector) {
43         injector.container.configure.register!Tool(new T,"tool.cmd."~Cmd);
44     }
45     override void registerAppDependencies(DefaultInjector injector) {
46         //sharedLog.trace("ToolsModule registerAppDependencies()");
47         registerTool!("init",InitTool)(injector);
48         registerTool!("install",InstallTool)(injector);
49         registerTool!("lang",LangTool)(injector);
50         registerTool!("cfg",CfgTool)(injector);
51     }
52 
53 };
54 
55 struct Options {
56 };
57 
58 int main(string[] args) {
59     auto m = new ToolsModule;
60     MsgLog.info(ToolConfig.tools.applicationName);
61     Options opt;
62     auto rslt = getopt(args
63     );
64     if (rslt.helpWanted) {
65         defaultGetoptPrinter(ToolConfig.tools.applicationName,
66             rslt.options);
67         return 0;
68     }
69     if(args.length < 2) {
70         defaultGetoptPrinter(ToolConfig.tools.applicationName,
71             rslt.options);
72         return -1;
73     }
74     string cmd = args[1];
75     MsgLog.info("cmd = "~cmd);
76 
77     Tool tool;
78     try {
79         tool = resolveInjector!Tool("tool.cmd."~cmd);
80     } catch(Exception e) {
81         MsgLog.fatal(MsgText!(ToolConfig.toolsMessages.ERR_TOOL_NOT_FOUND)(cmd));
82         return -1;
83     }
84     MsgLog.trace("tool "~typeid(typeof(tool)).to!string);
85 
86     WorkflowElement[] elements = [ tool ];
87     elements[0] = tool;
88     auto wf = new DefaultWorkflow(elements,args);
89     
90     WorkflowRunner runner = resolveInjector!WorkflowRunner;
91     auto job = runner.createJob(wf);
92     job.execute;
93     
94     return 0;
95 }
96