You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provides a higher level API for command-line argument parsing than interacting
41
-
with `process.argv` directly.
43
+
with `process.argv` directly. Takes a specification for the expected arguments and returns a structured object with the parsed options and positionals.
42
44
43
45
```mjs
44
46
import { parseArgs } from'util';
@@ -133,7 +135,7 @@ This package was implemented using [tape](https://www.npmjs.com/package/tape) as
133
135
## 💡 `process.mainArgs` Proposal
134
136
135
137
> Note: This can be moved forward independently of the `util.parseArgs()` proposal/work.
*`multiple` {boolean} (Optional) If true, when appearing one or more times in `args`, results are collected in an `Array`
154
156
*`short` {string} (Optional) A single character alias for an option; When appearing one or more times in `args`; Respects the `multiple` configuration
155
157
*`strict` {Boolean} (Optional) A `Boolean` for whether or not to throw an error when unknown options are encountered, `type:'string'` options are missing an options-argument, or `type:'boolean'` options are passed an options-argument; defaults to `true`
158
+
*`allowPositionals` {Boolean} (Optional) Whether this command accepts positional arguments. Defaults `false` if `strict` is `true`, otherwise defaults to `true`.
156
159
* Returns: {Object} An object having properties:
157
160
*`values` {Object}, key:value for each option found. Value is a string for string options, or `true` for boolean options, or an array (of strings or booleans) for options configured as `multiple:true`.
Copy file name to clipboardExpand all lines: errors.js
+11-2Lines changed: 11 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -22,17 +22,26 @@ class ERR_PARSE_ARGS_INVALID_OPTION_VALUE extends Error {
22
22
}
23
23
24
24
classERR_PARSE_ARGS_UNKNOWN_OPTIONextendsError{
25
-
constructor(option){
26
-
super(`Unknown option '${option}'`);
25
+
constructor(option,allowPositionals){
26
+
constsuggestDashDash=allowPositionals ? `. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- ${JSON.stringify(option)}` : '';
0 commit comments