1 module unit_threaded.options; 2 3 import std.getopt; 4 import std.stdio; 5 import std.random; 6 import std.exception; 7 8 9 struct Options { 10 bool multiThreaded; 11 string[] testsToRun; 12 bool debugOutput; 13 bool list; 14 bool exit; 15 bool forceEscCodes; 16 bool random; 17 uint seed; 18 } 19 20 /** 21 * Parses the command-line args and returns Options 22 */ 23 auto getOptions(string[] args) { 24 bool single; 25 bool debugOutput; 26 bool help; 27 bool list; 28 bool forceEscCodes; 29 bool random; 30 uint seed = unpredictableSeed; 31 32 getopt(args, 33 "single|s", &single, //single-threaded 34 "debug|d", &debugOutput, //print debug output 35 "esccodes|e", &forceEscCodes, 36 "help|h", &help, 37 "list|l", &list, 38 "random|r", &random, 39 "seed", &seed, 40 ); 41 42 if(help) { 43 writeln("Usage: <progname> <options> <tests>...\n", 44 "Options: \n", 45 " -h/--help: help\n" 46 " -s/--single: single-threaded\n", 47 " -l/--list: list tests\n", 48 " -d/--debug: enable debug output\n", 49 " -e/--esccodes: force ANSI escape codes even for !isatty\n", 50 " -r/--random: run tests in random order\n", 51 " --seed: set the seed for the random order\n", 52 ); 53 } 54 55 if(debugOutput) { 56 if(!single) { 57 writeln("-d implies -s, running in a single thread\n"); 58 } 59 single = true; 60 } 61 62 if(random) { 63 if(!single) writeln("-r implies -s, running in a single thread\n"); 64 single = true; 65 } 66 67 immutable exit = help || list; 68 return Options(!single, args[1..$], debugOutput, list, exit, forceEscCodes, 69 random, seed); 70 }