1 /** 2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved. 3 License: MPL-2 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 6 This Source Code Form is subject to the terms of the Mozilla Public License, 7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain 8 one at http://mozilla.org/MPL/2.0/. 9 10 This file contains an optional main function suitable for plugins. 11 12 It takes care of configuring the logging level in std.experimental.logger if 13 the user call the program with "-d|--debug". 14 15 This optional main function requires that: 16 - the module is named dextool.plugin.runner 17 - the module provides a function runPlugin that takes the program arguments. 18 */ 19 module dextool.plugin.main.standard; 20 21 import dextool.type : FileName, ExitStatusType; 22 23 /** Parse the raw command line. 24 */ 25 auto parseLogLevel(string[] args) { 26 import std.algorithm : findAmong; 27 import std.array : empty; 28 import dextool.logger_conf : ConfigureLog; 29 30 return findAmong(args, ["-d", "--debug"]).empty ? ConfigureLog.info : ConfigureLog.debug_; 31 } 32 33 int main(string[] args) { 34 import std.algorithm : filter, among; 35 import std.array : array; 36 import std.stdio : writeln; 37 import dextool.logger_conf : confLogLevel; 38 39 confLogLevel(parseLogLevel(args)); 40 41 // holds the remining arguments after -d/--debug has bee removed 42 auto remining_args = args.filter!(a => !a.among("-d", "--debug")).array(); 43 44 // REQUIRED BY PLUGINS USING THIS MAIN 45 import dextool.plugin.runner : runPlugin; 46 47 return runPlugin(remining_args); 48 }