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.tool.tool; 23 24 private import ctini.ctini; 25 private import aermicioi.aedi; 26 private import eph.args; 27 28 private import std.getopt; 29 private import std.conv; 30 private import std.experimental.logger; 31 private import std.meta; 32 private import std.typecons; 33 34 private import dxx.util; 35 private import dxx.util.ini; 36 private import dxx.app; 37 private import dxx.tool; 38 private import dxx.tools; 39 private import dxx.app.platform; 40 41 mixin __Text!(ToolConfig.tools.lang); 42 43 alias ToolsParam = Tuple!( 44 Tuple!( 45 Tuple!( 46 string,"interactive" 47 ),"cons" 48 ), "cmd", 49 //Tuple!( 50 // string,"target" 51 //), "init", 52 Tuple!( 53 string,"projectType", 54 string[],"dependencies" 55 ), "project", 56 Tuple!( 57 Tuple!( 58 string[],"type", 59 string[],"define" 60 ), "args" 61 ), "dxx" 62 ); 63 64 interface ToolsModuleInterface { 65 public ArgParser getArgParser(); 66 } 67 68 @component 69 class ToolsModule : PlatformRuntime!( 70 ToolsParam,ToolsModule 71 ),ToolsModuleInterface { 72 static void registerTool(alias Cmd : string,T : Tool)(InjectionContainer injector) { 73 injector.register!T("tool.cmd."~Cmd); 74 } 75 override void registerPlatformDependencies(InjectionContainer injector) { 76 debug { 77 sharedLog.trace("ToolsModule registerPlatformDependencies()"); 78 } 79 super.registerPlatformDependencies(injector); 80 registerTool!("init",InitTool)(injector); 81 registerTool!("install",InstallTool)(injector); 82 registerTool!("lang",LangTool)(injector); 83 registerTool!("cfg",ConfigTool)(injector); 84 registerTool!("cons",ConsoleTool)(injector); 85 registerTool!("work",WorkflowTool)(injector); 86 87 //InitTool.registerArguments(injector); 88 //InstallTool.registerArguments(injector); 89 //LangTool.registerArguments(injector); 90 //CfgTool.registerArguments(injector); 91 } 92 93 @component 94 override ArgParser getArgParser() { 95 debug { 96 sharedLog.trace("Get Args Parser"); 97 } 98 return new ArgParser; 99 } 100 mixin registerComponent!ToolsModule; 101 }; 102 103 104 version (DXX_Developer) { 105 // ... 106 } else { 107 struct Options { 108 string[] inFiles; 109 }; 110 111 int main(string[] args) { 112 MsgLog.info(ToolConfig.tools.applicationName); 113 114 Options opt; 115 auto rslt = getopt(args, 116 std.getopt.config.passThrough, 117 "infile|i", &opt.inFiles 118 ); 119 if (rslt.helpWanted) { 120 defaultGetoptPrinter(ToolConfig.tools.applicationName, 121 rslt.options); 122 return 0; 123 } 124 if(args.length < 2) { 125 defaultGetoptPrinter(ToolConfig.tools.applicationName, 126 rslt.options); 127 return -1; 128 } 129 130 string cmd = args[1]; 131 MsgLog.info("Command: ",cmd); 132 133 //auto loader = new PluginLoader("examples/plugin/bin/dxx_example-plugin.dll"); 134 //loader.update; 135 136 Tool tool; 137 try { 138 tool = resolveInjector!Tool("tool.cmd."~cmd); 139 } catch(Exception e) { 140 MsgLog.fatal(MsgText!(ToolConfig.toolsMessages.ERR_TOOL_NOT_FOUND)(cmd)); 141 return -1; 142 } 143 WorkflowElement[] elements = [ tool ]; 144 auto wf = new DefaultWorkflow(elements,args); 145 146 WorkflowRunner runner = resolveInjector!WorkflowRunner; 147 auto job = runner.createJob(wf); 148 DXXPlatform.executeJob(job); 149 150 return 0; 151 } 152 153 }