Skip to content

Commit 4f9bc3e

Browse files
nhz-ioljharb
authored andcommittedOct 18, 2022
[Fix] opt.string works with multiple aliases (#10)
Fixes #9.
1 parent ef9153f commit 4f9bc3e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed
 

‎index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ module.exports = function (args, opts) {
8585
[].concat(opts.string).filter(Boolean).forEach(function (key) {
8686
flags.strings[key] = true;
8787
if (aliases[key]) {
88-
flags.strings[aliases[key]] = true;
88+
[].concat(aliases[key]).forEach(function (k) {
89+
flags.strings[k] = true;
90+
});
8991
}
9092
});
9193

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"prepublish": "not-in-publish || npm run prepublishOnly",
2020
"lint": "eslint --ext=js,mjs .",
2121
"pretest": "npm run lint",
22-
"tests-only": "nyc tape test/*.js",
22+
"tests-only": "nyc tape 'test/**/*.js'",
2323
"test": "npm run tests-only",
2424
"posttest": "aud --production",
2525
"version": "auto-changelog && git add CHANGELOG.md",

‎test/parse.js

+11
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ test('string and alias', function (t) {
142142
t.equal(typeof y.str, 'string');
143143
t.equal(y.s, '000123');
144144
t.equal(typeof y.s, 'string');
145+
146+
var z = parse(['-s123'], {
147+
alias: { str: ['s', 'S'] },
148+
string: ['str'],
149+
});
150+
151+
t.deepEqual(
152+
z,
153+
{ _: [], s: '123', S: '123', str: '123' },
154+
'opt.string works with multiple aliases'
155+
);
145156
t.end();
146157
});
147158

0 commit comments

Comments
 (0)
Please sign in to comment.