1
1
'use strict' ;
2
2
3
3
const {
4
- ArrayPrototypeConcat,
5
4
ArrayPrototypeForEach,
5
+ ArrayPrototypeIncludes,
6
6
ArrayPrototypeShift,
7
7
ArrayPrototypeSlice,
8
8
ArrayPrototypePush,
9
+ ArrayPrototypePushApply,
10
+ ArrayPrototypeUnshiftApply,
9
11
ObjectEntries,
10
12
ObjectPrototypeHasOwnProperty : ObjectHasOwn ,
11
13
StringPrototypeCharAt,
12
- StringPrototypeIncludes,
13
14
StringPrototypeIndexOf,
14
15
StringPrototypeSlice,
15
16
} = require ( './primordials' ) ;
@@ -32,7 +33,7 @@ const {
32
33
isShortOptionAndValue,
33
34
isShortOptionGroup,
34
35
objectGetOwn,
35
- optionsGetOwn
36
+ optionsGetOwn,
36
37
} = require ( './utils' ) ;
37
38
38
39
const {
@@ -48,29 +49,29 @@ function getMainArgs() {
48
49
// This function is a placeholder for proposed process.mainArgs.
49
50
// Work out where to slice process.argv for user supplied arguments.
50
51
51
- // Electron is an interested example, with work-arounds implemented in
52
+ // Electron is an interesting example, with workarounds implemented in
52
53
// Commander and Yargs. Hopefully Electron would support process.mainArgs
53
- // itself and render this work-around moot.
54
+ // itself and render this workaround moot.
54
55
//
55
56
// In a bundled Electron app, the user CLI args directly
56
57
// follow executable. (No special processing required for unbundled.)
57
58
// 1) process.versions.electron is either set by electron, or undefined
58
- // see https://github.com/electron/electron/blob/master/ docs/api/process.md #processversionselectron-readonly
59
+ // see: https://www.electronjs.org/ docs/latest/ api/process#processversionselectron-readonly
59
60
// 2) process.defaultApp is undefined in a bundled Electron app, and set
60
61
// in an unbundled Electron app
61
- // see https://github.com/electron/electron/blob/master/ docs/api/process.md#processversionselectron -readonly
62
+ // see: https://www.electronjs.org/ docs/latest/ api/process#processdefaultapp -readonly
62
63
// (Not included in tests as hopefully temporary example.)
63
64
/* c8 ignore next 3 */
64
- if ( process . versions && process . versions . electron && ! process . defaultApp ) {
65
+ if ( process . versions ? .electron && ! process . defaultApp ) {
65
66
return ArrayPrototypeSlice ( process . argv , 1 ) ;
66
67
}
67
68
68
69
// Check node options for scenarios where user CLI args follow executable.
69
70
const execArgv = process . execArgv ;
70
- if ( StringPrototypeIncludes ( execArgv , '-e' ) ||
71
- StringPrototypeIncludes ( execArgv , '--eval' ) ||
72
- StringPrototypeIncludes ( execArgv , '-p' ) ||
73
- StringPrototypeIncludes ( execArgv , '--print' ) ) {
71
+ if ( ArrayPrototypeIncludes ( execArgv , '-e' ) ||
72
+ ArrayPrototypeIncludes ( execArgv , '--eval' ) ||
73
+ ArrayPrototypeIncludes ( execArgv , '-p' ) ||
74
+ ArrayPrototypeIncludes ( execArgv , '--print' ) ) {
74
75
return ArrayPrototypeSlice ( process . argv , 1 ) ;
75
76
}
76
77
@@ -107,6 +108,7 @@ To specify an option argument starting with a dash use ${example}.`;
107
108
* @param {object } options - option configs, from parseArgs({ options })
108
109
* @param {string } shortOrLong - option used, with dashes e.g. `-l` or `--long`
109
110
* @param {boolean } strict - show errors, from parseArgs({ strict })
111
+ * @param {boolean } allowPositionals - from parseArgs({ allowPositionals })
110
112
*/
111
113
function checkOptionUsage ( longOption , optionValue , options ,
112
114
shortOrLong , strict , allowPositionals ) {
@@ -203,7 +205,7 @@ const parseArgs = (config = { __proto__: null }) => {
203
205
positionals : [ ]
204
206
} ;
205
207
206
- let remainingArgs = ArrayPrototypeSlice ( args ) ;
208
+ const remainingArgs = ArrayPrototypeSlice ( args ) ;
207
209
while ( remainingArgs . length > 0 ) {
208
210
const arg = ArrayPrototypeShift ( remainingArgs ) ;
209
211
const nextArg = remainingArgs [ 0 ] ;
@@ -216,7 +218,7 @@ const parseArgs = (config = { __proto__: null }) => {
216
218
}
217
219
218
220
// Everything after a bare '--' is considered a positional argument.
219
- result . positionals = ArrayPrototypeConcat (
221
+ ArrayPrototypePushApply (
220
222
result . positionals ,
221
223
remainingArgs
222
224
) ;
@@ -257,7 +259,7 @@ const parseArgs = (config = { __proto__: null }) => {
257
259
break ; // finished short group
258
260
}
259
261
}
260
- remainingArgs = ArrayPrototypeConcat ( expanded , remainingArgs ) ;
262
+ ArrayPrototypeUnshiftApply ( remainingArgs , expanded ) ;
261
263
continue ;
262
264
}
263
265
@@ -309,5 +311,5 @@ const parseArgs = (config = { __proto__: null }) => {
309
311
} ;
310
312
311
313
module . exports = {
312
- parseArgs
314
+ parseArgs,
313
315
} ;
0 commit comments