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,17 @@ 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+ await generate ( generatorList ( { language, client, clientList } ) , Boolean ( withDebugger ) ) ;
6264 } ) ;
6365
6466const buildCommand = program . command ( 'build' ) . description ( 'Build the clients or specs' ) ;
@@ -68,7 +70,7 @@ buildCommand
6870 . description ( 'Build a specified client' )
6971 . addArgument ( args . language )
7072 . addArgument ( args . clients )
71- . option ( flags . verbose . flag , flags . verbose . description )
73+ . addOption ( flags . verbose )
7274 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
7375 const { language, client, clientList } = transformSelection ( {
7476 langArg,
@@ -85,7 +87,7 @@ buildCommand
8587 . description ( 'Build a specified playground' )
8688 . addArgument ( args . language )
8789 . addArgument ( args . clients )
88- . option ( flags . verbose . flag , flags . verbose . description )
90+ . addOption ( flags . verbose )
8991 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
9092 const { language, client, clientList } = transformSelection ( {
9193 langArg,
@@ -102,7 +104,7 @@ buildCommand
102104 . description ( 'Build a specified snippets' )
103105 . addArgument ( args . language )
104106 . addArgument ( args . clients )
105- . option ( flags . verbose . flag , flags . verbose . description )
107+ . addOption ( flags . verbose )
106108 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
107109 const { language, client, clientList } = transformSelection ( {
108110 langArg,
@@ -119,7 +121,7 @@ buildCommand
119121 . description ( 'Build a specified guides' )
120122 . addArgument ( args . language )
121123 . addArgument ( args . clients )
122- . option ( flags . verbose . flag , flags . verbose . description )
124+ . addOption ( flags . verbose )
123125 . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
124126 const { language, client, clientList } = transformSelection ( {
125127 langArg,
@@ -135,7 +137,7 @@ buildCommand
135137 . command ( 'specs' )
136138 . description ( 'Build a specified spec' )
137139 . addArgument ( args . clients )
138- . option ( flags . verbose . flag , flags . verbose . description )
140+ . addOption ( flags . verbose )
139141 . option ( '-s, --skip-cache' , 'skip cache checking to force building specs' )
140142 . option ( '-j, --json' , 'outputs the spec in JSON instead of yml' )
141143 . option ( '-d, --docs' , 'generates the doc specs with the code snippets' )
@@ -172,25 +174,26 @@ ctsCommand
172174 . description ( 'Generate the CTS tests' )
173175 . addArgument ( args . language )
174176 . addArgument ( args . clients )
175- . option ( flags . verbose . flag , flags . verbose . description )
177+ . addOption ( flags . verbose )
178+ . addOption ( flags . debugger )
176179 . option ( '--lv, --language-version <version>' , 'the version of the language to use' )
177- . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, languageVersion } ) => {
180+ . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, debugger : withDebugger , languageVersion } ) => {
178181 const { language, client, clientList } = transformSelection ( {
179182 langArg,
180183 clientArg,
181184 } ) ;
182185
183186 setVerbose ( Boolean ( verbose ) ) ;
184187
185- await ctsGenerateMany ( generatorList ( { language, client, clientList } ) , languageVersion ) ;
188+ await ctsGenerateMany ( generatorList ( { language, client, clientList } ) , withDebugger , languageVersion ) ;
186189 } ) ;
187190
188191ctsCommand
189192 . command ( 'run' )
190193 . description ( 'Run the tests for the CTS' )
191194 . addArgument ( args . language )
192195 . addArgument ( args . clients )
193- . option ( flags . verbose . flag , flags . verbose . description )
196+ . addOption ( flags . verbose )
194197 . option ( '-e, --no-e2e' , 'skip the e2e tests, that requires internet connection' )
195198 . option ( '-c, --no-client' , 'skip the client tests' )
196199 . option ( '-r, --no-requests' , 'skip the requests tests' )
@@ -250,7 +253,7 @@ program
250253 . description ( 'Format the specified folder for a specific language' )
251254 . addArgument ( args . requiredLanguage )
252255 . argument ( 'folder' , 'The folder to format' )
253- . option ( flags . verbose . flag , flags . verbose . description )
256+ . addOption ( flags . verbose )
254257 . action ( async ( language : string , folder : string , { verbose } ) => {
255258 setVerbose ( Boolean ( verbose ) ) ;
256259
@@ -262,25 +265,27 @@ program
262265 . description ( 'Generate the snippets' )
263266 . addArgument ( args . language )
264267 . addArgument ( args . clients )
265- . option ( flags . verbose . flag , flags . verbose . description )
266- . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
268+ . addOption ( flags . verbose )
269+ . addOption ( flags . debugger )
270+ . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, debugger : withDebugger } ) => {
267271 const { language, client, clientList } = transformSelection ( {
268272 langArg,
269273 clientArg,
270274 } ) ;
271275
272276 setVerbose ( Boolean ( verbose ) ) ;
273277
274- await docsGenerateMany ( generatorList ( { language, client, clientList } ) , 'snippets' ) ;
278+ await docsGenerateMany ( generatorList ( { language, client, clientList } ) , 'snippets' , Boolean ( withDebugger ) ) ;
275279 } ) ;
276280
277281program
278282 . command ( 'guides' )
279283 . description ( 'Generate the guides' )
280284 . addArgument ( args . language )
281285 . addArgument ( args . clients )
282- . option ( flags . verbose . flag , flags . verbose . description )
283- . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose } ) => {
286+ . addOption ( flags . verbose )
287+ . addOption ( flags . debugger )
288+ . action ( async ( langArg : LangArg , clientArg : string [ ] , { verbose, debugger : withDebugger } ) => {
284289 const { language, client, clientList } = transformSelection ( {
285290 langArg,
286291 clientArg,
@@ -293,13 +298,14 @@ program
293298 existsSync ( toAbsolutePath ( `templates/${ gen . language } /guides/${ gen . client } ` ) ) ,
294299 ) ,
295300 'guides' ,
301+ Boolean ( withDebugger ) ,
296302 ) ;
297303 } ) ;
298304
299305program
300306 . command ( 'release' )
301307 . description ( 'Releases the client' )
302- . option ( flags . verbose . flag , flags . verbose . description )
308+ . addOption ( flags . verbose )
303309 . option < semver . ReleaseType > (
304310 '--rt --release-type <type>' ,
305311 'triggers a release for the given language list with the given releaseType' ,
0 commit comments