1 module cucumber.commandline; 2 3 import std.getopt; 4 5 import cucumber.formatter; 6 import cucumber.result : RunResult; 7 import cucumber.runner : CucumberRunner; 8 import gherkin : GherkinDocument, Parser, getFeatureFiles; 9 import glob : glob; 10 11 /** 12 * CucumberCommandLine 13 */ 14 class CucumberCommandline 15 { 16 /** 17 * run 18 * 19 * Returns: 20 * exit code 21 */ 22 int run(ModuleNames...)(string[] args) 23 { 24 string format; 25 bool dryRun; 26 bool noColor; 27 bool quiet; 28 bool noSnippets; 29 bool noSource; 30 // dfmt off 31 auto opts = getopt(args, 32 "d|dry-run", "Invokes formatters without executing the steps.", 33 &dryRun, 34 "f|format", "How to format features (Default: pretty). Available formats: 35 pretty : Prints the feature as is - in colours. 36 progress : Prints one character per scenario.", 37 &format, 38 "no-color", "Whether or not to use ANSI color in the output.", 39 &noColor, 40 "i|no-snippets", "Don't print snippets for pending steps.", 41 &noSnippets, 42 "s|no-source", "Don't print the file and line of the step definition with the steps.", 43 &noSource, 44 "q|quiet", "Alias for --no-snippets --no-source.", 45 &quiet, 46 std.getopt.config.passThrough); 47 // dfmt on 48 noSnippets |= quiet; 49 noSource |= quiet; 50 51 if (opts.helpWanted) 52 { 53 defaultGetoptPrinter("Usage: cucumber [options]", opts.options); 54 return 0; 55 } 56 57 Formatter formatter; 58 switch (format) 59 { 60 case "progress": 61 formatter = new Progress(noColor, noSnippets, noSource); 62 break; 63 case "pretty": 64 default: 65 formatter = new Pretty(noColor, noSnippets, noSource); 66 } 67 auto runner = new CucumberRunner(formatter, dryRun); 68 auto featureFiles = getFeatureFiles(args); 69 RunResult result; 70 71 foreach (featureFile; featureFiles) 72 { 73 // TODO: Throw No such file error if file does not exit 74 auto gherkinDocument = Parser.parseFromFile(featureFile); 75 76 result += runner.runFeature!ModuleNames(gherkinDocument); 77 } 78 79 formatter.summarizeResult(result); 80 81 return result.exitCode; 82 } 83 }