1 module options; 2 3 import std.getopt; 4 import dubproxy.options : DubProxyOptions; 5 6 @safe: 7 8 struct DubProxyCliOptions { 9 import dubproxy.git : TagKind; 10 DubProxyOptions libOptions; 11 bool verbose; 12 13 bool mirrorCodeDlang; 14 string mirrorFilename = "code.json"; 15 string[] packages; 16 string proxyFile = "dubproxy.json"; 17 string packageFolder = getDefaultPackageFolder(); 18 string gitFolder = getDefaultPackageFolder(); 19 20 bool dummyDubProxy; 21 string dummyDubProxyPath = "."; 22 23 string showTagsPath; 24 TagKind tagKind = TagKind.all; 25 26 bool cloneAll; 27 bool cloneAllNoTerminal; 28 bool genAllTags; 29 } 30 31 private DubProxyCliOptions __options; 32 33 ref DubProxyCliOptions writeAbleOptions() { 34 return __options; 35 } 36 37 @property ref const(DubProxyCliOptions) options() { 38 return __options; 39 } 40 41 string getDefaultPackageFolder() pure { 42 version(Posix) { 43 return "~/.dub/packages/"; 44 } else version(Windows) { 45 return `%APPDATA%\dub\packages\`; 46 } else { 47 static assert(false, "Unsupported platform"); 48 } 49 } 50 51 string getDefaultGitFolder() pure { 52 version(Posix) { 53 return "~/.dub/DubProxyGits/"; 54 } else version(Windows) { 55 return `%APPDATA%\dub\DubProxyGits\`; 56 } else { 57 static assert(false, "Unsupported platform"); 58 } 59 } 60 61 62 GetoptResult parseOptions(ref string[] args) { 63 auto helpInformation = getopt(args, 64 "m|mirror", 65 "Get a list of packages currently available on code.dlang.org" 66 ~ "\n\t\t\tand store a file specified in \"n|mirrorFileName\"", 67 &writeAbleOptions().mirrorCodeDlang, 68 69 "n|mirrorFileName", 70 "The filename where to store the packages available on code.dlang.org", 71 &writeAbleOptions().mirrorFilename, 72 73 "d|dubPath", 74 "The path to the dub executable", 75 &writeAbleOptions().libOptions.pathToDub, 76 77 "p|gitPath", 78 "The path to the git executable", 79 &writeAbleOptions().libOptions.pathToGit, 80 81 "f|gitFolder", 82 "The path where the gits get cloned to", 83 &writeAbleOptions().gitFolder, 84 85 "overrideGit", 86 "Allow to override the git folder of cloned packages", 87 &writeAbleOptions().libOptions.ovrGF, 88 89 "overrideTree", 90 "Allow to override the git worktree folder of cloned package version", 91 &writeAbleOptions().libOptions.ovrWTF, 92 93 "g|get", 94 "Get a precific package. \"-g dub\" will fetch dub and create" 95 ~ "\n\t\t\tfolders for all version tags for dub. \"-g dub:1.1.0\" will " 96 ~ "\n\t\t\ttry to get dub and create a package for v1.1.0. " 97 ~ "\n\t\t\t\"g dub:~master\" will try get dub and create a package for " 98 ~ "\n\t\t\t~master", 99 &writeAbleOptions().packages, 100 101 "i|proxyFile", 102 "The filename of the dubproxy file to search packages in", 103 &writeAbleOptions().proxyFile, 104 105 "o|packagesFolder", 106 "The path where packages should be stored", 107 &writeAbleOptions().packageFolder, 108 109 "dummy", 110 "Generate a empty dubproxy.json file", 111 &writeAbleOptions().dummyDubProxy, 112 113 "dummyPath", 114 "Path to the folder where to create the dummy dubproxy.json file", 115 &writeAbleOptions().dummyDubProxyPath, 116 117 "t|tags", 118 "Show tags for passed dirpath or url", 119 &writeAbleOptions().showTagsPath, 120 121 "k|tagsKind", 122 "Limit tags to a specific kind of tags", 123 &writeAbleOptions().tagKind, 124 125 "a|cloneAll", 126 "Clone or fetch all packages provided in \"i|input\"", 127 &writeAbleOptions().cloneAll, 128 129 "u|noUserInteraction", 130 "Run git without user interaction", 131 &writeAbleOptions().libOptions.noUserInteraction, 132 133 "v|verbose", 134 "Get some more output of what is going on", 135 &writeAbleOptions().verbose, 136 137 "genAllTags", 138 "Generate tags for all the repos in gitFolder listed in proxyFile", 139 &writeAbleOptions().genAllTags, 140 ); 141 142 return helpInformation; 143 }