@@ -38,12 +38,17 @@ import {
38
38
import { devHandler , devOptions } from "./dev" ;
39
39
import { workerNamespaceCommands } from "./dispatch-namespace" ;
40
40
import { docsHandler , docsOptions } from "./docs" ;
41
- import { JsonFriendlyFatalError , UserError } from "./errors" ;
41
+ import {
42
+ CommandLineArgsError ,
43
+ JsonFriendlyFatalError ,
44
+ UserError ,
45
+ } from "./errors" ;
42
46
import { generateHandler , generateOptions } from "./generate" ;
43
47
import { hyperdrive } from "./hyperdrive/index" ;
44
48
import { initHandler , initOptions } from "./init" ;
45
49
import "./kv" ;
46
50
import "./workflows" ;
51
+ import { demandSingleValue } from "./core" ;
47
52
import { logBuildFailure , logger , LOGGER_LEVELS } from "./logger" ;
48
53
import * as metrics from "./metrics" ;
49
54
import { mTlsCertificateCommands } from "./mtls-certificate/cli" ;
@@ -159,35 +164,6 @@ export function getLegacyScriptName(
159
164
: args . name ?? config . name ;
160
165
}
161
166
162
- /**
163
- * A helper to demand one of a set of options
164
- * via https://github.com/yargs/yargs/issues/1093#issuecomment-491299261
165
- */
166
- export function demandOneOfOption ( ...options : string [ ] ) {
167
- return function ( argv : { [ key : string ] : unknown } ) {
168
- const count = options . filter ( ( option ) => argv [ option ] ) . length ;
169
- const lastOption = options . pop ( ) ;
170
-
171
- if ( count === 0 ) {
172
- throw new CommandLineArgsError (
173
- `Exactly one of the arguments ${ options . join (
174
- ", "
175
- ) } and ${ lastOption } is required`
176
- ) ;
177
- } else if ( count > 1 ) {
178
- throw new CommandLineArgsError (
179
- `Arguments ${ options . join (
180
- ", "
181
- ) } and ${ lastOption } are mutually exclusive`
182
- ) ;
183
- }
184
-
185
- return true ;
186
- } ;
187
- }
188
-
189
- export class CommandLineArgsError extends UserError { }
190
-
191
167
export function createCLIParser ( argv : string [ ] ) {
192
168
const experimentalGradualRollouts =
193
169
// original flag -- using internal product name (Gradual Rollouts) -- kept for temp back-compat
@@ -230,12 +206,14 @@ export function createCLIParser(argv: string[]) {
230
206
type : "string" ,
231
207
requiresArg : true ,
232
208
} )
209
+ . check ( demandSingleValue ( "config" ) )
233
210
. option ( "env" , {
234
211
alias : "e" ,
235
212
describe : "Environment to use for operations and .env files" ,
236
213
type : "string" ,
237
214
requiresArg : true ,
238
215
} )
216
+ . check ( demandSingleValue ( "env" ) )
239
217
. option ( "experimental-json-config" , {
240
218
alias : "j" ,
241
219
describe : `Experimental: support wrangler.json` ,
0 commit comments