11'use strict' ;
22
33const {
4- ArrayPrototypeConcat,
54 ArrayPrototypeForEach,
5+ ArrayPrototypeIncludes,
66 ArrayPrototypeShift,
77 ArrayPrototypeSlice,
88 ArrayPrototypePush,
9+ ArrayPrototypePushApply,
10+ ArrayPrototypeUnshiftApply,
911 ObjectEntries,
1012 ObjectPrototypeHasOwnProperty : ObjectHasOwn ,
1113 StringPrototypeCharAt,
12- StringPrototypeIncludes,
1314 StringPrototypeIndexOf,
1415 StringPrototypeSlice,
1516} = require ( './primordials' ) ;
@@ -32,7 +33,7 @@ const {
3233 isShortOptionAndValue,
3334 isShortOptionGroup,
3435 objectGetOwn,
35- optionsGetOwn
36+ optionsGetOwn,
3637} = require ( './utils' ) ;
3738
3839const {
@@ -48,29 +49,29 @@ function getMainArgs() {
4849 // This function is a placeholder for proposed process.mainArgs.
4950 // Work out where to slice process.argv for user supplied arguments.
5051
51- // Electron is an interested example, with work-arounds implemented in
52+ // Electron is an interesting example, with workarounds implemented in
5253 // Commander and Yargs. Hopefully Electron would support process.mainArgs
53- // itself and render this work-around moot.
54+ // itself and render this workaround moot.
5455 //
5556 // In a bundled Electron app, the user CLI args directly
5657 // follow executable. (No special processing required for unbundled.)
5758 // 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
5960 // 2) process.defaultApp is undefined in a bundled Electron app, and set
6061 // 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
6263 // (Not included in tests as hopefully temporary example.)
6364 /* c8 ignore next 3 */
64- if ( process . versions && process . versions . electron && ! process . defaultApp ) {
65+ if ( process . versions ? .electron && ! process . defaultApp ) {
6566 return ArrayPrototypeSlice ( process . argv , 1 ) ;
6667 }
6768
6869 // Check node options for scenarios where user CLI args follow executable.
6970 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' ) ) {
7475 return ArrayPrototypeSlice ( process . argv , 1 ) ;
7576 }
7677
@@ -107,6 +108,7 @@ To specify an option argument starting with a dash use ${example}.`;
107108 * @param {object } options - option configs, from parseArgs({ options })
108109 * @param {string } shortOrLong - option used, with dashes e.g. `-l` or `--long`
109110 * @param {boolean } strict - show errors, from parseArgs({ strict })
111+ * @param {boolean } allowPositionals - from parseArgs({ allowPositionals })
110112 */
111113function checkOptionUsage ( longOption , optionValue , options ,
112114 shortOrLong , strict , allowPositionals ) {
@@ -203,7 +205,7 @@ const parseArgs = (config = { __proto__: null }) => {
203205 positionals : [ ]
204206 } ;
205207
206- let remainingArgs = ArrayPrototypeSlice ( args ) ;
208+ const remainingArgs = ArrayPrototypeSlice ( args ) ;
207209 while ( remainingArgs . length > 0 ) {
208210 const arg = ArrayPrototypeShift ( remainingArgs ) ;
209211 const nextArg = remainingArgs [ 0 ] ;
@@ -216,7 +218,7 @@ const parseArgs = (config = { __proto__: null }) => {
216218 }
217219
218220 // Everything after a bare '--' is considered a positional argument.
219- result . positionals = ArrayPrototypeConcat (
221+ ArrayPrototypePushApply (
220222 result . positionals ,
221223 remainingArgs
222224 ) ;
@@ -257,7 +259,7 @@ const parseArgs = (config = { __proto__: null }) => {
257259 break ; // finished short group
258260 }
259261 }
260- remainingArgs = ArrayPrototypeConcat ( expanded , remainingArgs ) ;
262+ ArrayPrototypeUnshiftApply ( remainingArgs , expanded ) ;
261263 continue ;
262264 }
263265
@@ -309,5 +311,5 @@ const parseArgs = (config = { __proto__: null }) => {
309311} ;
310312
311313module . exports = {
312- parseArgs
314+ parseArgs,
313315} ;
0 commit comments