Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flag's aliases from the flags property #108

Merged
merged 10 commits into from
Feb 20, 2019
10 changes: 10 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ module.exports = (helpText, options) => {
delete argv._;

const flags = camelcaseKeys(argv, {exclude: ['--', /^\w$/]});
const simpleFlags = camelcaseKeys(argv, {exclude: ['--', /^\w$/]});
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved

if (options.flags !== undefined) {
Object.keys(options.flags).forEach(flag => {
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
if (options.flags[flag].alias !== undefined) {
delete simpleFlags[options.flags[flag].alias];
}
});
}

return {
input,
flags,
simpleFlags,
pkg,
help,
showHelp,
Expand Down
22 changes: 22 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,25 @@ test('grouped short-flags work', t => {
t.true(flags.c);
t.true(flags.l);
});

test('grouped flags work', t => {
const cli = meow({
argv: ['-cl'],
flags: {
coco: {
type: 'boolean',
alias: 'c'
},
loco: {
type: 'boolean',
alias: 'l'
}
}
});

const {simpleFlags} = cli;
t.true(simpleFlags.coco);
t.true(simpleFlags.loco);
t.is(simpleFlags.c, undefined);
t.is(simpleFlags.l, undefined);
});