yargs 15.3.1 → 15.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +2 -3
  3. package/README.md +5 -5
  4. package/build/lib/apply-extends.d.ts +2 -0
  5. package/build/lib/apply-extends.js +65 -0
  6. package/build/lib/argsert.d.ts +2 -0
  7. package/build/lib/argsert.js +65 -0
  8. package/build/lib/command.d.ts +64 -0
  9. package/build/lib/command.js +416 -0
  10. package/build/lib/common-types.d.ts +36 -0
  11. package/build/lib/common-types.js +25 -0
  12. package/build/lib/completion-templates.d.ts +2 -0
  13. package/{lib → build/lib}/completion-templates.js +6 -5
  14. package/build/lib/completion.d.ts +21 -0
  15. package/build/lib/completion.js +135 -0
  16. package/build/lib/is-promise.d.ts +1 -0
  17. package/build/lib/is-promise.js +9 -0
  18. package/build/lib/levenshtein.d.ts +1 -0
  19. package/{lib → build/lib}/levenshtein.js +33 -33
  20. package/build/lib/middleware.d.ts +10 -0
  21. package/build/lib/middleware.js +57 -0
  22. package/build/lib/obj-filter.d.ts +1 -0
  23. package/build/lib/obj-filter.js +14 -0
  24. package/build/lib/parse-command.d.ts +11 -0
  25. package/build/lib/parse-command.js +36 -0
  26. package/build/lib/process-argv.d.ts +2 -0
  27. package/build/lib/process-argv.js +31 -0
  28. package/build/lib/usage.d.ts +49 -0
  29. package/build/lib/usage.js +540 -0
  30. package/build/lib/validation.d.ts +34 -0
  31. package/build/lib/validation.js +330 -0
  32. package/build/lib/yargs.d.ts +274 -0
  33. package/build/lib/yargs.js +1190 -0
  34. package/build/lib/yerror.d.ts +4 -0
  35. package/build/lib/yerror.js +11 -0
  36. package/index.js +1 -1
  37. package/locales/ja.json +6 -4
  38. package/package.json +26 -13
  39. package/yargs.js +2 -1291
  40. package/lib/apply-extends.js +0 -67
  41. package/lib/argsert.js +0 -68
  42. package/lib/command.js +0 -462
  43. package/lib/completion.js +0 -132
  44. package/lib/is-promise.js +0 -3
  45. package/lib/middleware.js +0 -64
  46. package/lib/obj-filter.js +0 -11
  47. package/lib/process-argv.js +0 -34
  48. package/lib/usage.js +0 -571
  49. package/lib/validation.js +0 -394
  50. package/lib/yerror.js +0 -11
@@ -1,67 +0,0 @@
1
-
2
- 'use strict'
3
- const fs = require('fs')
4
- const path = require('path')
5
- const YError = require('./yerror')
6
-
7
- let previouslyVisitedConfigs = []
8
-
9
- function checkForCircularExtends (cfgPath) {
10
- if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
11
- throw new YError(`Circular extended configurations: '${cfgPath}'.`)
12
- }
13
- }
14
-
15
- function getPathToDefaultConfig (cwd, pathToExtend) {
16
- return path.resolve(cwd, pathToExtend)
17
- }
18
-
19
- function mergeDeep (config1, config2) {
20
- const target = {}
21
- const isObject = obj => obj && typeof obj === 'object' && !Array.isArray(obj)
22
- Object.assign(target, config1)
23
- for (const key of Object.keys(config2)) {
24
- if (isObject(config2[key]) && isObject(target[key])) {
25
- target[key] = mergeDeep(config1[key], config2[key])
26
- } else {
27
- target[key] = config2[key]
28
- }
29
- }
30
- return target
31
- }
32
-
33
- function applyExtends (config, cwd, mergeExtends) {
34
- let defaultConfig = {}
35
-
36
- if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
37
- if (typeof config.extends !== 'string') return defaultConfig
38
- const isPath = /\.json|\..*rc$/.test(config.extends)
39
- let pathToDefault = null
40
- if (!isPath) {
41
- try {
42
- pathToDefault = require.resolve(config.extends)
43
- } catch (err) {
44
- // most likely this simply isn't a module.
45
- }
46
- } else {
47
- pathToDefault = getPathToDefaultConfig(cwd, config.extends)
48
- }
49
- // maybe the module uses key for some other reason,
50
- // err on side of caution.
51
- if (!pathToDefault && !isPath) return config
52
-
53
- checkForCircularExtends(pathToDefault)
54
-
55
- previouslyVisitedConfigs.push(pathToDefault)
56
-
57
- defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
58
- delete config.extends
59
- defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault), mergeExtends)
60
- }
61
-
62
- previouslyVisitedConfigs = []
63
-
64
- return mergeExtends ? mergeDeep(defaultConfig, config) : Object.assign({}, defaultConfig, config)
65
- }
66
-
67
- module.exports = applyExtends
package/lib/argsert.js DELETED
@@ -1,68 +0,0 @@
1
- 'use strict'
2
-
3
- // hoisted due to circular dependency on command.
4
- module.exports = argsert
5
- const command = require('./command')()
6
- const YError = require('./yerror')
7
-
8
- const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']
9
- function argsert (expected, callerArguments, length) {
10
- // TODO: should this eventually raise an exception.
11
- try {
12
- // preface the argument description with "cmd", so
13
- // that we can run it through yargs' command parser.
14
- let position = 0
15
- let parsed = { demanded: [], optional: [] }
16
- if (typeof expected === 'object') {
17
- length = callerArguments
18
- callerArguments = expected
19
- } else {
20
- parsed = command.parseCommand(`cmd ${expected}`)
21
- }
22
- const args = [].slice.call(callerArguments)
23
-
24
- while (args.length && args[args.length - 1] === undefined) args.pop()
25
- length = length || args.length
26
-
27
- if (length < parsed.demanded.length) {
28
- throw new YError(`Not enough arguments provided. Expected ${parsed.demanded.length} but received ${args.length}.`)
29
- }
30
-
31
- const totalCommands = parsed.demanded.length + parsed.optional.length
32
- if (length > totalCommands) {
33
- throw new YError(`Too many arguments provided. Expected max ${totalCommands} but received ${length}.`)
34
- }
35
-
36
- parsed.demanded.forEach((demanded) => {
37
- const arg = args.shift()
38
- const observedType = guessType(arg)
39
- const matchingTypes = demanded.cmd.filter(type => type === observedType || type === '*')
40
- if (matchingTypes.length === 0) argumentTypeError(observedType, demanded.cmd, position, false)
41
- position += 1
42
- })
43
-
44
- parsed.optional.forEach((optional) => {
45
- if (args.length === 0) return
46
- const arg = args.shift()
47
- const observedType = guessType(arg)
48
- const matchingTypes = optional.cmd.filter(type => type === observedType || type === '*')
49
- if (matchingTypes.length === 0) argumentTypeError(observedType, optional.cmd, position, true)
50
- position += 1
51
- })
52
- } catch (err) {
53
- console.warn(err.stack)
54
- }
55
- }
56
-
57
- function guessType (arg) {
58
- if (Array.isArray(arg)) {
59
- return 'array'
60
- } else if (arg === null) {
61
- return 'null'
62
- }
63
- return typeof arg
64
- }
65
-
66
- function argumentTypeError (observedType, allowedTypes, position, optional) {
67
- throw new YError(`Invalid ${positionName[position] || 'manyith'} argument. Expected ${allowedTypes.join(' or ')} but received ${observedType}.`)
68
- }
package/lib/command.js DELETED
@@ -1,462 +0,0 @@
1
- 'use strict'
2
-
3
- const inspect = require('util').inspect
4
- const isPromise = require('./is-promise')
5
- const { applyMiddleware, commandMiddlewareFactory } = require('./middleware')
6
- const path = require('path')
7
- const Parser = require('yargs-parser')
8
-
9
- const DEFAULT_MARKER = /(^\*)|(^\$0)/
10
-
11
- // handles parsing positional arguments,
12
- // and populating argv with said positional
13
- // arguments.
14
- module.exports = function command (yargs, usage, validation, globalMiddleware) {
15
- const self = {}
16
- let handlers = {}
17
- let aliasMap = {}
18
- let defaultCommand
19
- globalMiddleware = globalMiddleware || []
20
-
21
- self.addHandler = function addHandler (cmd, description, builder, handler, commandMiddleware) {
22
- let aliases = []
23
- const middlewares = commandMiddlewareFactory(commandMiddleware)
24
- handler = handler || (() => {})
25
-
26
- if (Array.isArray(cmd)) {
27
- aliases = cmd.slice(1)
28
- cmd = cmd[0]
29
- } else if (typeof cmd === 'object') {
30
- let command = (Array.isArray(cmd.command) || typeof cmd.command === 'string') ? cmd.command : moduleName(cmd)
31
- if (cmd.aliases) command = [].concat(command).concat(cmd.aliases)
32
- self.addHandler(command, extractDesc(cmd), cmd.builder, cmd.handler, cmd.middlewares)
33
- return
34
- }
35
-
36
- // allow a module to be provided instead of separate builder and handler
37
- if (typeof builder === 'object' && builder.builder && typeof builder.handler === 'function') {
38
- self.addHandler([cmd].concat(aliases), description, builder.builder, builder.handler, builder.middlewares)
39
- return
40
- }
41
-
42
- // parse positionals out of cmd string
43
- const parsedCommand = self.parseCommand(cmd)
44
-
45
- // remove positional args from aliases only
46
- aliases = aliases.map(alias => self.parseCommand(alias).cmd)
47
-
48
- // check for default and filter out '*''
49
- let isDefault = false
50
- const parsedAliases = [parsedCommand.cmd].concat(aliases).filter((c) => {
51
- if (DEFAULT_MARKER.test(c)) {
52
- isDefault = true
53
- return false
54
- }
55
- return true
56
- })
57
-
58
- // standardize on $0 for default command.
59
- if (parsedAliases.length === 0 && isDefault) parsedAliases.push('$0')
60
-
61
- // shift cmd and aliases after filtering out '*'
62
- if (isDefault) {
63
- parsedCommand.cmd = parsedAliases[0]
64
- aliases = parsedAliases.slice(1)
65
- cmd = cmd.replace(DEFAULT_MARKER, parsedCommand.cmd)
66
- }
67
-
68
- // populate aliasMap
69
- aliases.forEach((alias) => {
70
- aliasMap[alias] = parsedCommand.cmd
71
- })
72
-
73
- if (description !== false) {
74
- usage.command(cmd, description, isDefault, aliases)
75
- }
76
-
77
- handlers[parsedCommand.cmd] = {
78
- original: cmd,
79
- description: description,
80
- handler,
81
- builder: builder || {},
82
- middlewares,
83
- demanded: parsedCommand.demanded,
84
- optional: parsedCommand.optional
85
- }
86
-
87
- if (isDefault) defaultCommand = handlers[parsedCommand.cmd]
88
- }
89
-
90
- self.addDirectory = function addDirectory (dir, context, req, callerFile, opts) {
91
- opts = opts || {}
92
- // disable recursion to support nested directories of subcommands
93
- if (typeof opts.recurse !== 'boolean') opts.recurse = false
94
- // exclude 'json', 'coffee' from require-directory defaults
95
- if (!Array.isArray(opts.extensions)) opts.extensions = ['js']
96
- // allow consumer to define their own visitor function
97
- const parentVisit = typeof opts.visit === 'function' ? opts.visit : o => o
98
- // call addHandler via visitor function
99
- opts.visit = function visit (obj, joined, filename) {
100
- const visited = parentVisit(obj, joined, filename)
101
- // allow consumer to skip modules with their own visitor
102
- if (visited) {
103
- // check for cyclic reference
104
- // each command file path should only be seen once per execution
105
- if (~context.files.indexOf(joined)) return visited
106
- // keep track of visited files in context.files
107
- context.files.push(joined)
108
- self.addHandler(visited)
109
- }
110
- return visited
111
- }
112
- require('require-directory')({ require: req, filename: callerFile }, dir, opts)
113
- }
114
-
115
- // lookup module object from require()d command and derive name
116
- // if module was not require()d and no name given, throw error
117
- function moduleName (obj) {
118
- const mod = require('which-module')(obj)
119
- if (!mod) throw new Error(`No command name given for module: ${inspect(obj)}`)
120
- return commandFromFilename(mod.filename)
121
- }
122
-
123
- // derive command name from filename
124
- function commandFromFilename (filename) {
125
- return path.basename(filename, path.extname(filename))
126
- }
127
-
128
- function extractDesc (obj) {
129
- for (let keys = ['describe', 'description', 'desc'], i = 0, l = keys.length, test; i < l; i++) {
130
- test = obj[keys[i]]
131
- if (typeof test === 'string' || typeof test === 'boolean') return test
132
- }
133
- return false
134
- }
135
-
136
- self.parseCommand = function parseCommand (cmd) {
137
- const extraSpacesStrippedCommand = cmd.replace(/\s{2,}/g, ' ')
138
- const splitCommand = extraSpacesStrippedCommand.split(/\s+(?![^[]*]|[^<]*>)/)
139
- const bregex = /\.*[\][<>]/g
140
- const parsedCommand = {
141
- cmd: (splitCommand.shift()).replace(bregex, ''),
142
- demanded: [],
143
- optional: []
144
- }
145
- splitCommand.forEach((cmd, i) => {
146
- let variadic = false
147
- cmd = cmd.replace(/\s/g, '')
148
- if (/\.+[\]>]/.test(cmd) && i === splitCommand.length - 1) variadic = true
149
- if (/^\[/.test(cmd)) {
150
- parsedCommand.optional.push({
151
- cmd: cmd.replace(bregex, '').split('|'),
152
- variadic
153
- })
154
- } else {
155
- parsedCommand.demanded.push({
156
- cmd: cmd.replace(bregex, '').split('|'),
157
- variadic
158
- })
159
- }
160
- })
161
- return parsedCommand
162
- }
163
-
164
- self.getCommands = () => Object.keys(handlers).concat(Object.keys(aliasMap))
165
-
166
- self.getCommandHandlers = () => handlers
167
-
168
- self.hasDefaultCommand = () => !!defaultCommand
169
-
170
- self.runCommand = function runCommand (command, yargs, parsed, commandIndex) {
171
- let aliases = parsed.aliases
172
- const commandHandler = handlers[command] || handlers[aliasMap[command]] || defaultCommand
173
- const currentContext = yargs.getContext()
174
- let numFiles = currentContext.files.length
175
- const parentCommands = currentContext.commands.slice()
176
-
177
- // what does yargs look like after the builder is run?
178
- let innerArgv = parsed.argv
179
- let innerYargs = null
180
- let positionalMap = {}
181
- if (command) {
182
- currentContext.commands.push(command)
183
- currentContext.fullCommands.push(commandHandler.original)
184
- }
185
- if (typeof commandHandler.builder === 'function') {
186
- // a function can be provided, which builds
187
- // up a yargs chain and possibly returns it.
188
- innerYargs = commandHandler.builder(yargs.reset(parsed.aliases))
189
- if (!innerYargs || (typeof innerYargs._parseArgs !== 'function')) {
190
- innerYargs = yargs
191
- }
192
- if (shouldUpdateUsage(innerYargs)) {
193
- innerYargs.getUsageInstance().usage(
194
- usageFromParentCommandsCommandHandler(parentCommands, commandHandler),
195
- commandHandler.description
196
- )
197
- }
198
- innerArgv = innerYargs._parseArgs(null, null, true, commandIndex)
199
- aliases = innerYargs.parsed.aliases
200
- } else if (typeof commandHandler.builder === 'object') {
201
- // as a short hand, an object can instead be provided, specifying
202
- // the options that a command takes.
203
- innerYargs = yargs.reset(parsed.aliases)
204
- if (shouldUpdateUsage(innerYargs)) {
205
- innerYargs.getUsageInstance().usage(
206
- usageFromParentCommandsCommandHandler(parentCommands, commandHandler),
207
- commandHandler.description
208
- )
209
- }
210
- Object.keys(commandHandler.builder).forEach((key) => {
211
- innerYargs.option(key, commandHandler.builder[key])
212
- })
213
- innerArgv = innerYargs._parseArgs(null, null, true, commandIndex)
214
- aliases = innerYargs.parsed.aliases
215
- }
216
-
217
- if (!yargs._hasOutput()) {
218
- positionalMap = populatePositionals(commandHandler, innerArgv, currentContext, yargs)
219
- }
220
-
221
- const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares)
222
- applyMiddleware(innerArgv, yargs, middlewares, true)
223
-
224
- // we apply validation post-hoc, so that custom
225
- // checks get passed populated positional arguments.
226
- if (!yargs._hasOutput()) yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error)
227
-
228
- if (commandHandler.handler && !yargs._hasOutput()) {
229
- yargs._setHasOutput()
230
- // to simplify the parsing of positionals in commands,
231
- // we temporarily populate '--' rather than _, with arguments
232
- const populateDoubleDash = !!yargs.getOptions().configuration['populate--']
233
- if (!populateDoubleDash) yargs._copyDoubleDash(innerArgv)
234
-
235
- innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false)
236
- let handlerResult
237
- if (isPromise(innerArgv)) {
238
- handlerResult = innerArgv.then(argv => commandHandler.handler(argv))
239
- } else {
240
- handlerResult = commandHandler.handler(innerArgv)
241
- }
242
-
243
- const handlerFinishCommand = yargs.getHandlerFinishCommand()
244
- if (isPromise(handlerResult)) {
245
- yargs.getUsageInstance().cacheHelpMessage()
246
- handlerResult
247
- .then(value => {
248
- if (handlerFinishCommand) {
249
- handlerFinishCommand(value)
250
- }
251
- })
252
- .catch(error => {
253
- try {
254
- yargs.getUsageInstance().fail(null, error)
255
- } catch (err) {
256
- // fail's throwing would cause an unhandled rejection.
257
- }
258
- })
259
- .then(() => {
260
- yargs.getUsageInstance().clearCachedHelpMessage()
261
- })
262
- } else {
263
- if (handlerFinishCommand) {
264
- handlerFinishCommand(handlerResult)
265
- }
266
- }
267
- }
268
-
269
- if (command) {
270
- currentContext.commands.pop()
271
- currentContext.fullCommands.pop()
272
- }
273
- numFiles = currentContext.files.length - numFiles
274
- if (numFiles > 0) currentContext.files.splice(numFiles * -1, numFiles)
275
-
276
- return innerArgv
277
- }
278
-
279
- function shouldUpdateUsage (yargs) {
280
- return !yargs.getUsageInstance().getUsageDisabled() &&
281
- yargs.getUsageInstance().getUsage().length === 0
282
- }
283
-
284
- function usageFromParentCommandsCommandHandler (parentCommands, commandHandler) {
285
- const c = DEFAULT_MARKER.test(commandHandler.original) ? commandHandler.original.replace(DEFAULT_MARKER, '').trim() : commandHandler.original
286
- const pc = parentCommands.filter((c) => { return !DEFAULT_MARKER.test(c) })
287
- pc.push(c)
288
- return `$0 ${pc.join(' ')}`
289
- }
290
-
291
- self.runDefaultBuilderOn = function (yargs) {
292
- if (shouldUpdateUsage(yargs)) {
293
- // build the root-level command string from the default string.
294
- const commandString = DEFAULT_MARKER.test(defaultCommand.original)
295
- ? defaultCommand.original : defaultCommand.original.replace(/^[^[\]<>]*/, '$0 ')
296
- yargs.getUsageInstance().usage(
297
- commandString,
298
- defaultCommand.description
299
- )
300
- }
301
- const builder = defaultCommand.builder
302
- if (typeof builder === 'function') {
303
- builder(yargs)
304
- } else {
305
- Object.keys(builder).forEach((key) => {
306
- yargs.option(key, builder[key])
307
- })
308
- }
309
- }
310
-
311
- // transcribe all positional arguments "command <foo> <bar> [apple]"
312
- // onto argv.
313
- function populatePositionals (commandHandler, argv, context, yargs) {
314
- argv._ = argv._.slice(context.commands.length) // nuke the current commands
315
- const demanded = commandHandler.demanded.slice(0)
316
- const optional = commandHandler.optional.slice(0)
317
- const positionalMap = {}
318
-
319
- validation.positionalCount(demanded.length, argv._.length)
320
-
321
- while (demanded.length) {
322
- const demand = demanded.shift()
323
- populatePositional(demand, argv, positionalMap)
324
- }
325
-
326
- while (optional.length) {
327
- const maybe = optional.shift()
328
- populatePositional(maybe, argv, positionalMap)
329
- }
330
-
331
- argv._ = context.commands.concat(argv._)
332
-
333
- postProcessPositionals(argv, positionalMap, self.cmdToParseOptions(commandHandler.original))
334
-
335
- return positionalMap
336
- }
337
-
338
- function populatePositional (positional, argv, positionalMap, parseOptions) {
339
- const cmd = positional.cmd[0]
340
- if (positional.variadic) {
341
- positionalMap[cmd] = argv._.splice(0).map(String)
342
- } else {
343
- if (argv._.length) positionalMap[cmd] = [String(argv._.shift())]
344
- }
345
- }
346
-
347
- // we run yargs-parser against the positional arguments
348
- // applying the same parsing logic used for flags.
349
- function postProcessPositionals (argv, positionalMap, parseOptions) {
350
- // combine the parsing hints we've inferred from the command
351
- // string with explicitly configured parsing hints.
352
- const options = Object.assign({}, yargs.getOptions())
353
- options.default = Object.assign(parseOptions.default, options.default)
354
- options.alias = Object.assign(parseOptions.alias, options.alias)
355
- options.array = options.array.concat(parseOptions.array)
356
- delete options.config // don't load config when processing positionals.
357
-
358
- const unparsed = []
359
- Object.keys(positionalMap).forEach((key) => {
360
- positionalMap[key].map((value) => {
361
- if (options.configuration['unknown-options-as-args']) options.key[key] = true
362
- unparsed.push(`--${key}`)
363
- unparsed.push(value)
364
- })
365
- })
366
-
367
- // short-circuit parse.
368
- if (!unparsed.length) return
369
-
370
- const config = Object.assign({}, options.configuration, {
371
- 'populate--': true
372
- })
373
- const parsed = Parser.detailed(unparsed, Object.assign({}, options, {
374
- configuration: config
375
- }))
376
-
377
- if (parsed.error) {
378
- yargs.getUsageInstance().fail(parsed.error.message, parsed.error)
379
- } else {
380
- // only copy over positional keys (don't overwrite
381
- // flag arguments that were already parsed).
382
- const positionalKeys = Object.keys(positionalMap)
383
- Object.keys(positionalMap).forEach((key) => {
384
- [].push.apply(positionalKeys, parsed.aliases[key])
385
- })
386
-
387
- Object.keys(parsed.argv).forEach((key) => {
388
- if (positionalKeys.indexOf(key) !== -1) {
389
- // any new aliases need to be placed in positionalMap, which
390
- // is used for validation.
391
- if (!positionalMap[key]) positionalMap[key] = parsed.argv[key]
392
- argv[key] = parsed.argv[key]
393
- }
394
- })
395
- }
396
- }
397
-
398
- self.cmdToParseOptions = function (cmdString) {
399
- const parseOptions = {
400
- array: [],
401
- default: {},
402
- alias: {},
403
- demand: {}
404
- }
405
-
406
- const parsed = self.parseCommand(cmdString)
407
- parsed.demanded.forEach((d) => {
408
- const cmds = d.cmd.slice(0)
409
- const cmd = cmds.shift()
410
- if (d.variadic) {
411
- parseOptions.array.push(cmd)
412
- parseOptions.default[cmd] = []
413
- }
414
- cmds.forEach((c) => {
415
- parseOptions.alias[cmd] = c
416
- })
417
- parseOptions.demand[cmd] = true
418
- })
419
-
420
- parsed.optional.forEach((o) => {
421
- const cmds = o.cmd.slice(0)
422
- const cmd = cmds.shift()
423
- if (o.variadic) {
424
- parseOptions.array.push(cmd)
425
- parseOptions.default[cmd] = []
426
- }
427
- cmds.forEach((c) => {
428
- parseOptions.alias[cmd] = c
429
- })
430
- })
431
-
432
- return parseOptions
433
- }
434
-
435
- self.reset = () => {
436
- handlers = {}
437
- aliasMap = {}
438
- defaultCommand = undefined
439
- return self
440
- }
441
-
442
- // used by yargs.parse() to freeze
443
- // the state of commands such that
444
- // we can apply .parse() multiple times
445
- // with the same yargs instance.
446
- const frozens = []
447
- self.freeze = () => {
448
- const frozen = {}
449
- frozens.push(frozen)
450
- frozen.handlers = handlers
451
- frozen.aliasMap = aliasMap
452
- frozen.defaultCommand = defaultCommand
453
- }
454
- self.unfreeze = () => {
455
- const frozen = frozens.pop()
456
- handlers = frozen.handlers
457
- aliasMap = frozen.aliasMap
458
- defaultCommand = frozen.defaultCommand
459
- }
460
-
461
- return self
462
- }