1 /** 2 Copyright: Copyright (c) 2016-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 module dextool.plugin.types; 11 12 public import dextool.type : ExitStatusType; 13 14 /// CLI options that a plugin must implement. 15 struct CliBasicOption { 16 this(string p) { 17 payload = p; 18 } 19 20 string payload; 21 alias payload this; 22 23 invariant { 24 assert(payload.length > 0); 25 } 26 } 27 28 /// deprecated, moved to dextool.type 29 /// The raw arguments from the command line. 30 struct CliArgs { 31 string[] payload; 32 alias payload this; 33 } 34 35 /// The category the plugin is registered to handle. 36 struct CliCategory { 37 string payload; 38 alias payload this; 39 40 invariant { 41 assert(payload.length > 0); 42 } 43 } 44 45 /// A oneliner describing the category. 46 struct CliCategoryInfo { 47 string payload; 48 alias payload this; 49 50 invariant { 51 import std.ascii : newline; 52 import std.algorithm : splitter, sum, map; 53 54 assert(payload.length > 0); 55 // only one line 56 assert(payload.splitter(newline).map!(a => 1).sum == 1); 57 } 58 } 59 60 /// The three parts needed to construct a Docopt compatible string. 61 struct CliOptionParts { 62 string usage; 63 string optional; 64 string others; 65 } 66 67 /// Docopt compatible CLI string. 68 struct CliDocoptOption { 69 string payload; 70 alias payload this; 71 } 72 73 alias PluginFuncType = ExitStatusType function(CliBasicOption basic, CliArgs args); 74 75 struct Plugin { 76 CliCategory category; 77 CliCategoryInfo categoryCliInfo; 78 PluginFuncType func; 79 }