Skip to content

Commit 8ff2bcc

Browse files
committed
poke.js - cannot exit within an argument && default named exit option
1 parent 67197e6 commit 8ff2bcc

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ 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,
54+
}, k = o => o == null ? key : o, // undefined is ok?
5555
ask = (msg, val) => err({msg, i, opt, key, val}),
5656
exit = c => ({ i: i + c, key, opt });
5757
// prepare

poke.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const poke = (title, argv, req) => {
1111
$('⌨️ ', argv.length, argv);
1212
$('🔍', req);
1313
const res = {}, ret = parse(argv, 0, req, res, e);
14-
$('📖', res);
14+
$('🎁', res);
1515
$('😇', ret);
1616
$(hr);
1717
};
@@ -87,3 +87,31 @@ poke('My Dashes are undefined', ['awawaw', 'sdfsdf'], {
8787
poke('My Dashes are null', ['awawaw', 'sdfsdf'], {
8888
'--': null
8989
}); // But null is ok
90+
91+
poke('cannot exit within an argument && default named exit option', ['-abcd'], {
92+
a: { def: false, set: '-a' },
93+
b: '-b',
94+
'-c': undefined,
95+
'-d': null,
96+
});
97+
/*
98+
🤓 cannot exit within an argument && default named exit option
99+
⌨️ 1 [ '-abcd' ]
100+
🔍 { a: { def: false, set: '-a' }, b: '-b', '-c': undefined, '-d': null }
101+
💥 {
102+
msg: 'cannot exit within an argument',
103+
i: 0,
104+
opt: '-b',
105+
key: 'b',
106+
val: undefined
107+
}
108+
💥 {
109+
msg: 'invalid option',
110+
i: 0,
111+
opt: '-c',
112+
key: undefined,
113+
val: undefined
114+
}
115+
🎁 { a: true }
116+
😇 { i: 1, key: '-d', opt: '-d' }
117+
*/

0 commit comments

Comments
 (0)