1 /** 2 Copyright: Copyright (c) 2018, 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 module dextool.plugin.graphml.frontend.argsparser; 11 12 import logger = std.experimental.logger; 13 14 @safe: 15 16 struct RawConfiguration { 17 import std.getopt : GetoptResult, getopt, defaultGetoptPrinter; 18 19 string[] cflags; 20 string[] compileDb; 21 string[] fileExclude; 22 string[] fileRestrict; 23 string[] inFiles; 24 string filePrefix = "dextool_"; 25 string out_; 26 bool classInheritDep; 27 bool classMemberDep; 28 bool classMethod; 29 bool classParamDep; 30 bool help; 31 bool shortPluginHelp; 32 bool skipFileError; 33 34 string[] originalFlags; 35 36 private GetoptResult help_info; 37 38 void parse(string[] args) { 39 import std.getopt; 40 41 originalFlags = args.dup; 42 43 try { 44 // dfmt off 45 help_info = getopt(args, std.getopt.config.keepEndOfOptions, 46 "class-method", &classMethod, 47 "class-paramdep", &classParamDep, 48 "class-inheritdep", &classInheritDep, 49 "class-memberdep", &classMemberDep, 50 "compile-db", &compileDb, 51 "file-exclude", &fileExclude, 52 "file-prefix", &filePrefix, 53 "file-restrict", &fileRestrict, 54 "in", &inFiles, 55 "out", &out_, 56 "short-plugin-help", &shortPluginHelp, 57 "skip-file-error", &skipFileError, 58 ); 59 // dfmt on 60 61 help = help_info.helpWanted; 62 } 63 catch (std.getopt.GetOptException ex) { 64 logger.error(ex.msg); 65 help = true; 66 } 67 catch (Exception ex) { 68 logger.error(ex.msg); 69 help = true; 70 } 71 72 import std.algorithm : find; 73 import std.array : array; 74 import std.range : drop; 75 76 // at this point args contain "what is left". What is interesting then is those after "--". 77 cflags = args.find("--").drop(1).array(); 78 } 79 80 void printHelp() @trusted { 81 defaultGetoptPrinter("Usage: dextool mutate [options] [--in=] [-- CFLAGS...]", 82 help_info.options); 83 } 84 }