Skip to content

Commit 08f5b77

Browse files
committed
v3.2.2-beta :: fix ret.i when exit on anonymous arguments
1 parent 04bf311 commit 08f5b77

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ export default function parse(argv, i, req, res, err) {
5151
res[key] = !def;
5252
return false;
5353
} return true;
54-
}, k = o => o == null ? key : o, // split undefined? really?
54+
}, k = o => o == null ? key : o, // split undefined? hmm ugly
5555
ask = (msg, val) => err({msg, i, opt, key, val}),
56-
exit = () => ({ i: i + 1, key, opt });
56+
exit = c => ({ i: i + c, key, opt });
5757
// prepare
5858
/** @type {OptKeyMap} */
5959
const set_ = {}, rst_ = {}, exit_ = {};
@@ -74,7 +74,7 @@ export default function parse(argv, i, req, res, err) {
7474
const def = vk.def;
7575
res[key] = isA(def) ? def.slice() : def;
7676
for (const o of god(vk.set)) if (o!=='--') set_[k(o)] = key; else _key = key, _exit = false;
77-
for (const o of god(vk.rst)) if (o!=='--') rst_[k(o)] = key;
77+
for (const o of god(vk.rst)) if (o!=='--') rst_[k(o)] = key; // do not reset around
7878
}
7979
// process
8080
let ext = false;
@@ -89,8 +89,8 @@ export default function parse(argv, i, req, res, err) {
8989
if (s.length < 2 || s[0] !== '-') {
9090
if (key = set_[opt = s]) ext = noB();
9191
else if (key = rst_[opt]) rst();
92-
else if (key = exit_[opt]) return exit();
93-
else if (key = _key) if (_exit) return exit(); else set(s);
92+
else if (key = exit_[opt]) return exit(1);
93+
else if (key = _key) if (_exit) return exit(0); else set(s);
9494
else if (ask('invalid option')) return i;
9595
continue;
9696
}
@@ -109,7 +109,7 @@ export default function parse(argv, i, req, res, err) {
109109
opt = '-' + s[J];
110110
if (key = set_[opt]) ext = noB();
111111
else if (key = rst_[opt]) rst();
112-
else if (key = exit_[opt]) return exit();
112+
else if (key = exit_[opt]) return exit(1);
113113
else if (ask('invalid option')) return i;
114114
continue;
115115
}
@@ -120,7 +120,7 @@ export default function parse(argv, i, req, res, err) {
120120
// --opt ...
121121
if (key = set_[opt = s]) ext = noB();
122122
else if (key = rst_[opt]) rst();
123-
else if (key = exit_[opt]) return exit();
123+
else if (key = exit_[opt]) return exit(1);
124124
else if (ask('invalid option')) return i;
125125
continue;
126126
}
@@ -139,7 +139,7 @@ export default function parse(argv, i, req, res, err) {
139139
}
140140
opt = '--';
141141
if (key = _key) {
142-
if (_exit) return exit();
142+
if (_exit) return exit(1);
143143
const a = res[key], l = argv.length; ++i;
144144
if (isA(a)) while (i < l) a.push(argv[i++]);
145145
else if (i < l) res[key] = argv[(i = l) - 1];

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pargv-lite",
3-
"version": "3.2.0-beta",
3+
"version": "3.2.2-beta",
44
"description": "A lightning-fast, single-pass command line argument parser with structure validation",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)