@@ -338,6 +338,51 @@ if (proxy) {
338338}
339339
340340export function createCLIParser ( argv : string [ ] ) {
341+ const globalFlags = {
342+ v : {
343+ describe : "Show version number" ,
344+ alias : "version" ,
345+ type : "boolean" ,
346+ } ,
347+ cwd : {
348+ describe :
349+ "Run as if Wrangler was started in the specified directory instead of the current working directory" ,
350+ type : "string" ,
351+ requiresArg : true ,
352+ } ,
353+ config : {
354+ alias : "c" ,
355+ describe : "Path to Wrangler configuration file" ,
356+ type : "string" ,
357+ requiresArg : true ,
358+ } ,
359+ env : {
360+ alias : "e" ,
361+ describe :
362+ "Environment to use for operations, and for selecting .env and .dev.vars files" ,
363+ type : "string" ,
364+ requiresArg : true ,
365+ } ,
366+ "env-file" : {
367+ describe :
368+ "Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files" ,
369+ type : "string" ,
370+ array : true ,
371+ requiresArg : true ,
372+ } ,
373+ "experimental-remote-bindings" : {
374+ describe : `Experimental: Enable Remote Bindings` ,
375+ type : "boolean" ,
376+ hidden : true ,
377+ alias : [ "x-remote-bindings" ] ,
378+ } ,
379+ "experimental-provision" : {
380+ describe : `Experimental: Enable automatic resource provisioning` ,
381+ type : "boolean" ,
382+ hidden : true ,
383+ alias : [ "x-provision" ] ,
384+ } ,
385+ } as const ;
341386 // Type check result against CommonYargsOptions to make sure we've included
342387 // all common options
343388 const wrangler : CommonYargsArgv = makeCLI ( argv )
@@ -362,29 +407,13 @@ export function createCLIParser(argv: string[]) {
362407 // Define global options here, so they get included in the `Argv` type of
363408 // the `wrangler` variable
364409 . version ( false )
365- . option ( "v" , {
366- describe : "Show version number" ,
367- alias : "version" ,
368- type : "boolean" ,
369- } )
370- . option ( "cwd" , {
371- describe :
372- "Run as if Wrangler was started in the specified directory instead of the current working directory" ,
373- type : "string" ,
374- requiresArg : true ,
375- } )
410+ . options ( globalFlags )
376411 . check ( demandSingleValue ( "cwd" ) )
377412 . middleware ( ( _argv ) => {
378413 if ( _argv . cwd ) {
379414 process . chdir ( _argv . cwd ) ;
380415 }
381416 } )
382- . option ( "config" , {
383- alias : "c" ,
384- describe : "Path to Wrangler configuration file" ,
385- type : "string" ,
386- requiresArg : true ,
387- } )
388417 . check (
389418 demandSingleValue (
390419 "config" ,
@@ -394,38 +423,7 @@ export function createCLIParser(argv: string[]) {
394423 ( configArgv [ "_" ] [ 0 ] === "pages" && configArgv [ "_" ] [ 1 ] === "dev" )
395424 )
396425 )
397- . option ( "env" , {
398- alias : "e" ,
399- describe :
400- "Environment to use for operations, and for selecting .env and .dev.vars files" ,
401- type : "string" ,
402- requiresArg : true ,
403- } )
404- . option ( "env-file" , {
405- describe :
406- "Path to an .env file to load - can be specified multiple times - values from earlier files are overridden by values in later files" ,
407- type : "string" ,
408- array : true ,
409- requiresArg : true ,
410- } )
411426 . check ( demandSingleValue ( "env" ) )
412- . option ( "experimental-json-config" , {
413- alias : "j" ,
414- describe : `Support wrangler.json.` ,
415- type : "boolean" ,
416- default : true ,
417- deprecated : true ,
418- hidden : true ,
419- } )
420- . check ( ( args ) => {
421- if ( args [ "experimental-json-config" ] === false ) {
422- throw new CommandLineArgsError (
423- `Wrangler now supports wrangler.json configuration files by default and ignores the value of the \`--experimental-json-config\` flag.` ,
424- { telemetryMessage : true }
425- ) ;
426- }
427- return true ;
428- } )
429427 . check ( ( args ) => {
430428 // Set process environment params from `.env` files if available.
431429 const resolvedEnvFilePaths = (
@@ -447,18 +445,6 @@ export function createCLIParser(argv: string[]) {
447445
448446 return true ;
449447 } )
450- . option ( "experimental-remote-bindings" , {
451- describe : `Experimental: Enable Remote Bindings` ,
452- type : "boolean" ,
453- hidden : true ,
454- alias : [ "x-remote-bindings" ] ,
455- } )
456- . option ( "experimental-provision" , {
457- describe : `Experimental: Enable automatic resource provisioning` ,
458- type : "boolean" ,
459- hidden : true ,
460- alias : [ "x-provision" ] ,
461- } )
462448 . epilogue (
463449 `Please report any issues to ${ chalk . hex ( "#3B818D" ) (
464450 "https://github.com/cloudflare/workers-sdk/issues/new/choose"
@@ -1477,7 +1463,7 @@ export function createCLIParser(argv: string[]) {
14771463
14781464 wrangler . exitProcess ( false ) ;
14791465
1480- return { wrangler, registry } ;
1466+ return { wrangler, registry, globalFlags } ;
14811467}
14821468
14831469export async function main ( argv : string [ ] ) : Promise < void > {
0 commit comments