@@ -21,6 +21,33 @@ import * as info from '../lib/command/info.js';
2121
2222const program = new Command ( ) ;
2323
24+ const commandFlags = {
25+ ai : {
26+ flag : '--ai' ,
27+ description : 'enable AI assistant' ,
28+ } ,
29+ verbose : {
30+ flag : '--verbose' ,
31+ description : 'output internal logging information' ,
32+ } ,
33+ debug : {
34+ flag : '--debug' ,
35+ description : 'output additional information' ,
36+ } ,
37+ config : {
38+ flag : '-c, --config [file]' ,
39+ description : 'configuration file to be used' ,
40+ } ,
41+ profile : {
42+ flag : '--profile [value]' ,
43+ description : 'configuration profile to be used' ,
44+ } ,
45+ steps : {
46+ flag : '--steps' ,
47+ description : 'show step-by-step execution' ,
48+ } ,
49+ } ;
50+
2451const errorHandler = ( fn ) => async ( ...args ) => {
2552 try {
2653 await fn . default ( ...args ) ;
@@ -52,9 +79,10 @@ program.command('migrate [path]')
5279program . command ( 'shell [path]' )
5380 . alias ( 'sh' )
5481 . description ( 'Interactive shell' )
55- . option ( '--verbose' , 'output internal logging information' )
56- . option ( '--profile [value]' , 'configuration profile to be used' )
57- . option ( '-c, --config [file]' , 'configuration file to be used' )
82+ . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
83+ . option ( commandFlags . profile . flag , commandFlags . profile . description )
84+ . option ( commandFlags . ai . flag , commandFlags . ai . description )
85+ . option ( commandFlags . config . flag , commandFlags . config . description )
5886 . action ( errorHandler ( interactive ) ) ;
5987
6088program . command ( 'list [path]' )
@@ -64,27 +92,27 @@ program.command('list [path]')
6492
6593program . command ( 'def [path]' )
6694 . description ( 'Generates TypeScript definitions for all I actions.' )
67- . option ( '-c, -- config [file]' , 'configuration file to be used' )
95+ . option ( commandFlags . config . flag , commandFlags . config . description )
6896 . option ( '-o, --output [folder]' , 'target folder to paste definitions' )
6997 . action ( errorHandler ( definitions ) ) ;
7098
7199program . command ( 'gherkin:init [path]' )
72100 . alias ( 'bdd:init' )
73101 . description ( 'Prepare CodeceptJS to run feature files.' )
74- . option ( '-c, -- config [file]' , 'configuration file to be used' )
102+ . option ( commandFlags . config . flag , commandFlags . config . description )
75103 . action ( errorHandler ( gherkinInit ) ) ;
76104
77105program . command ( 'gherkin:steps [path]' )
78106 . alias ( 'bdd:steps' )
79107 . description ( 'Prints all defined gherkin steps.' )
80- . option ( '-c, -- config [file]' , 'configuration file to be used' )
108+ . option ( commandFlags . config . flag , commandFlags . config . description )
81109 . action ( errorHandler ( gherkinSteps ) ) ;
82110
83111program . command ( 'gherkin:snippets [path]' )
84112 . alias ( 'bdd:snippets' )
85113 . description ( 'Generate step definitions from steps.' )
86114 . option ( '--dry-run' , "don't save snippets to file" )
87- . option ( '-c, -- config [file]' , 'configuration file to be used' )
115+ . option ( commandFlags . config . flag , commandFlags . config . description )
88116 . option ( '--feature [file]' , 'feature files(s) to scan' )
89117 . option ( '--path [file]' , 'file in which to place the new snippets' )
90118 . action ( errorHandler ( gherkinSnippets ) ) ;
@@ -110,16 +138,22 @@ program.command('generate:helper [path]')
110138 . description ( 'Generates a new helper' )
111139 . action ( errorHandler ( generate . helper ) ) ;
112140
141+ program . command ( 'generate:heal [path]' )
142+ . alias ( 'gr' )
143+ . description ( 'Generates basic heal recipes' )
144+ . action ( errorHandler ( require ( '../lib/command/generate' ) . heal ) ) ;
145+
113146program . command ( 'run [test]' )
114147 . description ( 'Executes tests' )
115148
116149 // codecept-only options
117- . option ( '--steps' , 'show step-by-step execution' )
118- . option ( '--debug' , 'output additional information' )
119- . option ( '--verbose' , 'output internal logging information' )
150+ . option ( commandFlags . ai . flag , commandFlags . ai . description )
151+ . option ( commandFlags . steps . flag , commandFlags . steps . description )
152+ . option ( commandFlags . debug . flag , commandFlags . debug . description )
153+ . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
120154 . option ( '-o, --override [value]' , 'override current config options' )
121- . option ( '-- profile [value]' , 'configuration profile to be used' )
122- . option ( '-c, -- config [file]' , 'configuration file to be used' )
155+ . option ( commandFlags . profile . flag , commandFlags . profile . description )
156+ . option ( commandFlags . config . flag , commandFlags . config . description )
123157 . option ( '--features' , 'run only *.feature files and skip tests' )
124158 . option ( '--tests' , 'run only JS test files and skip features' )
125159 . option ( '--no-timeouts' , 'disable all timeouts' )
@@ -149,34 +183,36 @@ program.command('run [test]')
149183
150184program . command ( 'run-workers <workers> [selectedRuns...]' )
151185 . description ( 'Executes tests in workers' )
152- . option ( '-c, -- config [file]' , 'configuration file to be used' )
186+ . option ( commandFlags . config . flag , commandFlags . config . description )
153187 . option ( '-g, --grep <pattern>' , 'only run tests matching <pattern>' )
154188 . option ( '-i, --invert' , 'inverts --grep matches' )
155189 . option ( '-o, --override [value]' , 'override current config options' )
156190 . option ( '--suites' , 'parallel execution of suites not single tests' )
157- . option ( '-- debug' , 'output additional information' )
158- . option ( '-- verbose' , 'output internal logging information' )
191+ . option ( commandFlags . debug . flag , commandFlags . debug . description )
192+ . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
159193 . option ( '--features' , 'run only *.feature files and skip tests' )
160194 . option ( '--tests' , 'run only JS test files and skip features' )
161- . option ( '--profile [value]' , 'configuration profile to be used' )
195+ . option ( commandFlags . profile . flag , commandFlags . profile . description )
196+ . option ( commandFlags . ai . flag , commandFlags . ai . description )
162197 . option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
163198 . option ( '-O, --reporter-options <k=v,k2=v2,...>' , 'reporter-specific options' )
164199 . option ( '-R, --reporter <name>' , 'specify the reporter to use' )
165200 . action ( errorHandler ( runWorkers ) ) ;
166201
167202program . command ( 'run-multiple [suites...]' )
168203 . description ( 'Executes tests multiple' )
169- . option ( '-c, -- config [file]' , 'configuration file to be used' )
170- . option ( '-- profile [value]' , 'configuration profile to be used' )
204+ . option ( commandFlags . config . flag , commandFlags . config . description )
205+ . option ( commandFlags . profile . flag , commandFlags . profile . description )
171206 . option ( '--all' , 'run all suites' )
172207 . option ( '--features' , 'run only *.feature files and skip tests' )
173208 . option ( '--tests' , 'run only JS test files and skip features' )
209+ . option ( commandFlags . ai . flag , commandFlags . ai . description )
174210 . option ( '-g, --grep <pattern>' , 'only run tests matching <pattern>' )
175211 . option ( '-f, --fgrep <string>' , 'only run tests containing <string>' )
176212 . option ( '-i, --invert' , 'inverts --grep and --fgrep matches' )
177- . option ( '-- steps' , 'show step-by-step execution' )
178- . option ( '-- verbose' , 'output internal logging information' )
179- . option ( '-- debug' , 'output additional information' )
213+ . option ( commandFlags . steps . flag , commandFlags . steps . description )
214+ . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
215+ . option ( commandFlags . debug . flag , commandFlags . debug . description )
180216 . option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
181217 . option ( '-o, --override [value]' , 'override current config options' )
182218 . option ( '-O, --reporter-options <k=v,k2=v2,...>' , 'reporter-specific options' )
@@ -197,28 +233,28 @@ program.command('dry-run [test]')
197233 . description ( 'Prints step-by-step scenario for a test without actually running it' )
198234 . option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
199235 . option ( '--bootstrap' , 'enable bootstrap & teardown scripts for dry-run' )
200- . option ( '-c, -- config [file]' , 'configuration file to be used' )
236+ . option ( commandFlags . config . flag , commandFlags . config . description )
201237 . option ( '--all' , 'run all suites' )
202238 . option ( '--features' , 'run only *.feature files and skip tests' )
203239 . option ( '--tests' , 'run only JS test files and skip features' )
204240 . option ( '-g, --grep <pattern>' , 'only run tests matching <pattern>' )
205241 . option ( '-f, --fgrep <string>' , 'only run tests containing <string>' )
206242 . option ( '-i, --invert' , 'inverts --grep and --fgrep matches' )
207- . option ( '-- steps' , 'show step-by-step execution' )
208- . option ( '-- verbose' , 'output internal logging information' )
209- . option ( '-- debug' , 'output additional information' )
243+ . option ( commandFlags . steps . flag , commandFlags . steps . description )
244+ . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
245+ . option ( commandFlags . debug . flag , commandFlags . debug . description )
210246 . action ( errorHandler ( dryRun ) ) ;
211247
212248program . command ( 'run-rerun [test]' )
213249 . description ( 'Executes tests in more than one test suite run' )
214250
215251 // codecept-only options
216- . option ( '-- steps' , 'show step-by-step execution' )
217- . option ( '-- debug' , 'output additional information' )
218- . option ( '-- verbose' , 'output internal logging information' )
252+ . option ( commandFlags . steps . flag , commandFlags . steps . description )
253+ . option ( commandFlags . debug . flag , commandFlags . debug . description )
254+ . option ( commandFlags . verbose . flag , commandFlags . verbose . description )
219255 . option ( '-o, --override [value]' , 'override current config options' )
220- . option ( '-- profile [value]' , 'configuration profile to be used' )
221- . option ( '-c, -- config [file]' , 'configuration file to be used' )
256+ . option ( commandFlags . profile . flag , commandFlags . profile . description )
257+ . option ( commandFlags . config . flag , commandFlags . config . description )
222258 . option ( '--features' , 'run only *.feature files and skip tests' )
223259 . option ( '--tests' , 'run only JS test files and skip features' )
224260 . option ( '-p, --plugins <k=v,k2=v2,...>' , 'enable plugins, comma-separated' )
@@ -253,5 +289,6 @@ program.on('command:*', (cmd) => {
253289
254290if ( process . argv . length <= 2 ) {
255291 program . outputHelp ( ) ;
292+ } else {
293+ program . parse ( process . argv ) ;
256294}
257- program . parse ( process . argv ) ;
0 commit comments