|
1 | 1 | function Cli(argv) {
|
2 | 2 | var Cucumber = require('../cucumber');
|
| 3 | + var Command = require('commander').Command; |
| 4 | + var path = require('path'); |
| 5 | + |
| 6 | + function collect(val, memo) { |
| 7 | + memo.push(val); |
| 8 | + return memo; |
| 9 | + } |
| 10 | + |
| 11 | + function getConfiguration() { |
| 12 | + var program = getProgram(); |
| 13 | + program.parse(argv); |
| 14 | + var profileArgs = Cucumber.Cli.ProfilesLoader.getArgs(program.profile); |
| 15 | + argv.splice.apply(argv, [2, 0].concat(profileArgs)); |
| 16 | + program.parse(argv); |
| 17 | + var configuration = Cucumber.Cli.Configuration(program.opts(), program.args); |
| 18 | + return configuration; |
| 19 | + } |
| 20 | + |
| 21 | + function getProgram () { |
| 22 | + var program = new Command(path.basename(argv[1])); |
| 23 | + |
| 24 | + program |
| 25 | + .usage('[options] [<DIR|FILE[:LINE]>...]') |
| 26 | + .version(Cucumber.VERSION, '-v, --version') |
| 27 | + .option('-b, --backtrace', 'show full backtrace for errors') |
| 28 | + .option('--compiler <EXTENSION:MODULE>', 'require files with the given EXTENSION after requiring MODULE (repeatable)', collect, []) |
| 29 | + .option('-d, --dry-run', 'invoke formatters without executing steps') |
| 30 | + .option('--fail-fast', 'abort the run on first failure') |
| 31 | + .option('-f, --format <TYPE[:PATH]>', 'specify the output format, optionally supply PATH to redirect formatter output (repeatable)', collect, ['pretty']) |
| 32 | + .option('--no-colors', 'disable colors in formatter output') |
| 33 | + .option('--no-snippets', 'hide step definition snippets for pending steps') |
| 34 | + .option('--no-source', 'hide source uris') |
| 35 | + .option('-p, --profile <NAME>', 'specify the profile to use (repeatable)', collect, []) |
| 36 | + .option('-r, --require <FILE|DIR>', 'require files before executing features (repeatable)', collect, []) |
| 37 | + .option('--snippet-syntax <FILE>', 'specify a custom snippet syntax') |
| 38 | + .option('-S, --strict', 'fail if there are any undefined or pending steps') |
| 39 | + .option('-t, --tags <EXPRESSION>', 'only execute the features or scenarios with tags matching the expression (repeatable)', collect, []); |
| 40 | + |
| 41 | + program.on('--help', function(){ |
| 42 | + console.log(' For more details please visit https://github.com/cucumber/cucumber-js#cli\n'); |
| 43 | + }); |
| 44 | + |
| 45 | + return program; |
| 46 | + } |
3 | 47 |
|
4 | 48 | var self = {
|
5 | 49 | run: function run(callback) {
|
6 |
| - var configuration = Cli.Configuration(argv); |
7 |
| - if (configuration.isHelpRequested()) |
8 |
| - self.displayHelp(callback); |
9 |
| - else if (configuration.isVersionRequested()) |
10 |
| - self.displayVersion(callback); |
11 |
| - else |
12 |
| - self.runSuiteWithConfiguration(configuration, callback); |
13 |
| - }, |
14 |
| - |
15 |
| - runSuiteWithConfiguration: function runSuiteWithConfiguration(configuration, callback) { |
| 50 | + var configuration = getConfiguration(); |
16 | 51 | var runtime = Cucumber.Runtime(configuration);
|
17 | 52 | var formatters = configuration.getFormatters();
|
18 | 53 | formatters.forEach(function (formatter) {
|
19 | 54 | runtime.attachListener(formatter);
|
20 | 55 | });
|
21 | 56 | runtime.start(callback);
|
22 |
| - }, |
23 |
| - |
24 |
| - displayHelp: function displayHelp(callback) { |
25 |
| - /* jshint -W109 */ |
26 |
| - process.stdout.write("Usage: cucumber.js [options] [[FILE|DIR][:LINE]]+\n\ |
27 |
| -\n\ |
28 |
| --r, --require LIBRARY|DIR Require files before executing the features. If\n\ |
29 |
| - this option is not specified, all *.js and\n\ |
30 |
| - *.coffee files that are siblings or below the\n\ |
31 |
| - features will be loaded automatically. Automatic\n\ |
32 |
| - loading is disabled when this option is specified,\n\ |
33 |
| - and all loading becomes explicit.\n\ |
34 |
| -\n\ |
35 |
| - Files under directories named \"support\" are\n\ |
36 |
| - always loaded first.\n\ |
37 |
| -\n\ |
38 |
| --t, --tags TAG_EXPRESSION Only execute the features or scenarios with tags\n\ |
39 |
| - matching TAG_EXPRESSION. Scenarios inherit tags\n\ |
40 |
| - declared on the Feature level. The simplest\n\ |
41 |
| - TAG_EXPRESSION is simply a tag. Example:\n\ |
42 |
| - --tags @dev\n\ |
43 |
| -\n\ |
44 |
| - When a tag in a tag expression starts with a ~,\n\ |
45 |
| - this represents boolean NOT. Example:\n\ |
46 |
| - --tags ~@dev\n\ |
47 |
| -\n\ |
48 |
| - A tag expression can have several tags separated\n\ |
49 |
| - by a comma, which represents logical OR. Example:\n\ |
50 |
| - --tags @dev,@wip\n\ |
51 |
| -\n\ |
52 |
| - The --tags option can be specified several times,\n\ |
53 |
| - and this represents logical AND. Example:\n\ |
54 |
| - --tags @foo,~@bar --tags @zap.\n\ |
55 |
| -\n\ |
56 |
| - This represents the following boolean expression:\n\ |
57 |
| - (@foo || !@bar) && @zap.\n\ |
58 |
| -\n\ |
59 |
| - Beware that if you want to use several negative\n\ |
60 |
| - tags to exclude several tags you have to use\n\ |
61 |
| - logical AND: --tags ~@fixme --tags ~@buggy.\n\ |
62 |
| -\n\ |
63 |
| --f, --format FORMAT[:PATH] How to format features (default: progress).\n\ |
64 |
| - Supply PATH to redirect that formatters output.\n\ |
65 |
| - Available formats:\n\ |
66 |
| - pretty : prints the feature as is\n\ |
67 |
| - progress: prints one character per scenario\n\ |
68 |
| - json : prints the feature as JSON\n\ |
69 |
| - summary : prints a summary only, after all\n\ |
70 |
| - scenarios were executed\n\ |
71 |
| -\n\ |
72 |
| --p, --profile PROFILE Pull command line arguments from cucumber.js.\n\ |
73 |
| - When a 'default' profile is defined and no profile\n\ |
74 |
| - is specified it is always used.\n\ |
75 |
| -\n\ |
76 |
| ---compiler SUFFIX:MODULE Include step definitions and support files with the\n\ |
77 |
| - given file suffix and require the given module to\n\ |
78 |
| - load those files.\n\ |
79 |
| -\n\ |
80 |
| --i, --no-snippets Don't print snippets for pending steps.\n\ |
81 |
| -\n\ |
82 |
| ---snippet-syntax FILE Specify a custom snippet syntax.\n\ |
83 |
| -\n\ |
84 |
| --b, --backtrace Show full backtrace for all errors.\n\ |
85 |
| -\n\ |
86 |
| --S, --strict Fail if there are any undefined or pending steps.\n\ |
87 |
| -\n\ |
88 |
| --d, --dry-run Invokes formatters without executing the steps.\n\ |
89 |
| -\n\ |
90 |
| ---no-source Don't print the source uris.\n\ |
91 |
| -\n\ |
92 |
| ---[no-]colors Enable/disable colors in output.\n\ |
93 |
| -\n\ |
94 |
| ---fail-fast Abort the run on first failure.\n\ |
95 |
| -\n\ |
96 |
| --v, --version Display Cucumber.js's version.\n\ |
97 |
| -\n\ |
98 |
| --h, --help You're looking at it.\n"); |
99 |
| - /* jshint +W109 */ |
100 |
| - callback(true); |
101 |
| - }, |
102 |
| - |
103 |
| - displayVersion: function displayVersion(callback) { |
104 |
| - process.stdout.write(Cucumber.VERSION + '\n'); |
105 |
| - callback(true); |
106 | 57 | }
|
107 | 58 | };
|
108 | 59 | return self;
|
109 | 60 | }
|
110 | 61 |
|
111 |
| -Cli.ArgumentParser = require('./cli/argument_parser'); |
112 |
| -Cli.Configuration = require('./cli/configuration'); |
| 62 | +Cli.Configuration = require('./cli/configuration'); |
| 63 | +Cli.FeaturePathExpander = require('./cli/feature_path_expander'); |
113 | 64 | Cli.FeatureSourceLoader = require('./cli/feature_source_loader');
|
114 |
| -Cli.SupportCodeLoader = require('./cli/support_code_loader'); |
| 65 | +Cli.PathExpander = require('./cli/path_expander'); |
| 66 | +Cli.ProfilesLoader = require('./cli/profiles_loader'); |
| 67 | +Cli.SupportCodeLoader = require('./cli/support_code_loader'); |
| 68 | +Cli.SupportCodePathExpander = require('./cli/support_code_path_expander'); |
115 | 69 |
|
116 | 70 | module.exports = Cli;
|
0 commit comments