1- import { Argument , program } from 'commander' ;
1+ import { Argument , Option , program } from 'commander' ;
22import semver from 'semver' ;
33
44import { buildLanguages } from '../buildLanguages.ts' ;
@@ -29,10 +29,11 @@ const args = {
2929} ;
3030
3131const flags = {
32- verbose : {
33- flag : '-v, --verbose' ,
34- description : 'make the generation verbose' ,
35- } ,
32+ verbose : new Option ( '-v, --verbose' , 'make the generation verbose' ) ,
33+ debugger : new Option (
34+ '-d, --debugger' ,
35+ 'runs the generator in debug mode, it will wait for a Java debugger to be attached' ,
36+ ) ,
3637} ;
3738
3839program . name ( 'cli' ) ;
@@ -49,16 +50,19 @@ program
4950 . description ( 'Generate a specified client' )
5051 . addArgument ( args . language )
5152 . addArgument ( args . clients )
52- . option ( flags . verbose . flag , flags . verbose . description )
53- . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
53+ . addOption ( flags . verbose )
54+ . addOption ( flags . debugger )
55+ . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, debugger : withDebugger } ) => {
5456 const { language, client, clientList } = transformSelection ( {
5557 langArg,
5658 clientArg,
5759 } ) ;
5860
5961 setVerbose ( Boolean ( verbose ) ) ;
6062
61- await generate ( generatorList ( { language, client, clientList } ) ) ;
63+ console . log ( { withDebugger } ) ;
64+
65+ await generate ( generatorList ( { language, client, clientList } ) , Boolean ( withDebugger ) ) ;
6266 } ) ;
6367
6468const buildCommand = program . command ( 'build' ) . description ( 'Build the clients or specs' ) ;
@@ -68,7 +72,7 @@ buildCommand
6872 . description ( 'Build a specified client' )
6973 . addArgument ( args . language )
7074 . addArgument ( args . clients )
71- . option ( flags . verbose . flag , flags . verbose . description )
75+ . addOption ( flags . verbose )
7276 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
7377 const { language, client, clientList } = transformSelection ( {
7478 langArg,
@@ -85,7 +89,7 @@ buildCommand
8589 . description ( 'Build a specified playground' )
8690 . addArgument ( args . language )
8791 . addArgument ( args . clients )
88- . option ( flags . verbose . flag , flags . verbose . description )
92+ . addOption ( flags . verbose )
8993 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
9094 const { language, client, clientList } = transformSelection ( {
9195 langArg,
@@ -102,7 +106,7 @@ buildCommand
102106 . description ( 'Build a specified snippets' )
103107 . addArgument ( args . language )
104108 . addArgument ( args . clients )
105- . option ( flags . verbose . flag , flags . verbose . description )
109+ . addOption ( flags . verbose )
106110 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
107111 const { language, client, clientList } = transformSelection ( {
108112 langArg,
@@ -119,7 +123,7 @@ buildCommand
119123 . description ( 'Build a specified guides' )
120124 . addArgument ( args . language )
121125 . addArgument ( args . clients )
122- . option ( flags . verbose . flag , flags . verbose . description )
126+ . addOption ( flags . verbose )
123127 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
124128 const { language, client, clientList } = transformSelection ( {
125129 langArg,
@@ -135,7 +139,7 @@ buildCommand
135139 . command ( 'specs' )
136140 . description ( 'Build a specified spec' )
137141 . addArgument ( args . clients )
138- . option ( flags . verbose . flag , flags . verbose . description )
142+ . addOption ( flags . verbose )
139143 . option ( '-s, --skip-cache' , 'skip cache checking to force building specs' )
140144 . option ( '-j, --json' , 'outputs the spec in JSON instead of yml' )
141145 . option ( '-d, --docs' , 'generates the doc specs with the code snippets' )
@@ -172,25 +176,26 @@ ctsCommand
172176 . description ( 'Generate the CTS tests' )
173177 . addArgument ( args . language )
174178 . addArgument ( args . clients )
175- . option ( flags . verbose . flag , flags . verbose . description )
179+ . addOption ( flags . verbose )
180+ . addOption ( flags . debugger )
176181 . option ( '--lv, --language-version <version>' , 'the version of the language to use' )
177- . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, languageVersion } ) => {
182+ . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, debugger : withDebugger , languageVersion } ) => {
178183 const { language, client, clientList } = transformSelection ( {
179184 langArg,
180185 clientArg,
181186 } ) ;
182187
183188 setVerbose ( Boolean ( verbose ) ) ;
184189
185- await ctsGenerateMany ( generatorList ( { language, client, clientList } ) , languageVersion ) ;
190+ await ctsGenerateMany ( generatorList ( { language, client, clientList } ) , withDebugger , languageVersion ) ;
186191 } ) ;
187192
188193ctsCommand
189194 . command ( 'run' )
190195 . description ( 'Run the tests for the CTS' )
191196 . addArgument ( args . language )
192197 . addArgument ( args . clients )
193- . option ( flags . verbose . flag , flags . verbose . description )
198+ . addOption ( flags . verbose )
194199 . option ( '-e, --no-e2e' , 'skip the e2e tests, that requires internet connection' )
195200 . option ( '-c, --no-client' , 'skip the client tests' )
196201 . option ( '-r, --no-requests' , 'skip the requests tests' )
@@ -250,7 +255,7 @@ program
250255 . description ( 'Format the specified folder for a specific language' )
251256 . addArgument ( args . requiredLanguage )
252257 . argument ( 'folder' , 'The folder to format' )
253- . option ( flags . verbose . flag , flags . verbose . description )
258+ . addOption ( flags . verbose )
254259 . action ( async ( language : string , folder : string , { verbose } ) => {
255260 setVerbose ( Boolean ( verbose ) ) ;
256261
@@ -262,25 +267,27 @@ program
262267 . description ( 'Generate the snippets' )
263268 . addArgument ( args . language )
264269 . addArgument ( args . clients )
265- . option ( flags . verbose . flag , flags . verbose . description )
266- . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
270+ . addOption ( flags . verbose )
271+ . addOption ( flags . debugger )
272+ . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, debugger : withDebugger } ) => {
267273 const { language, client, clientList } = transformSelection ( {
268274 langArg,
269275 clientArg,
270276 } ) ;
271277
272278 setVerbose ( Boolean ( verbose ) ) ;
273279
274- await docsGenerateMany ( generatorList ( { language, client, clientList } ) , 'snippets' ) ;
280+ await docsGenerateMany ( generatorList ( { language, client, clientList } ) , 'snippets' , Boolean ( withDebugger ) ) ;
275281 } ) ;
276282
277283program
278284 . command ( 'guides' )
279285 . description ( 'Generate the guides' )
280286 . addArgument ( args . language )
281287 . addArgument ( args . clients )
282- . option ( flags . verbose . flag , flags . verbose . description )
283- . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
288+ . addOption ( flags . verbose )
289+ . addOption ( flags . debugger )
290+ . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, debugger : withDebugger } ) => {
284291 const { language, client, clientList } = transformSelection ( {
285292 langArg,
286293 clientArg,
@@ -293,13 +300,14 @@ program
293300 existsSync ( toAbsolutePath ( `templates/${ gen . language } /guides/${ gen . client } ` ) ) ,
294301 ) ,
295302 'guides' ,
303+ Boolean ( withDebugger ) ,
296304 ) ;
297305 } ) ;
298306
299307program
300308 . command ( 'release' )
301309 . description ( 'Releases the client' )
302- . option ( flags . verbose . flag , flags . verbose . description )
310+ . addOption ( flags . verbose )
303311 . option < semver . ReleaseType > (
304312 '--rt --release-type <type>' ,
305313 'triggers a release for the given language list with the given releaseType' ,
0 commit comments