Skip to content

Conversation

@coderaiser
Copy link
Contributor

@coderaiser coderaiser commented Oct 8, 2018

Hi, thank you for a great library :).

I'm using yargs-parser in a lot projects, one of them is redrun (CLI tool to run multiple npm-scripts fast). It has a couple 1 char aliases:

Usage: redrun [...tasks] [options] [-- ...args]
Options:
  -p, --parallel          run scripts in parallel
  -P, --parallel-calm     run scripts in parallel and return zero exit code

After updating to v11.0.0 some of my tests has failed, here is parsing:

const yargsParser = require('yargs-parser');
const result = yargsParser(['-p', 't*'], {
   array: [
     'parallel',
     'parallel-calm'
  ],
  alias: {
    'p': 'parallel',
    'P': 'parallel-calm'
  },
});

console.log(result);

And result:

{ _: [],
  p: [ 't*' ],
  P: [ 't*' ],
  'parallel-calm': [ 't*' ],
  parallelCalm: [ 't*' ],
  parallel: [],
}

the reason was yargs-parser handled p the same as P and parallel-calm, but it is parallel, actually.

The bug is located in condition of extendAliases function:

if (/[A-Z]/.test(x) && configuration['camel-case-expansion']) {
  var c = decamelize(x, '-')
   if (c !== key && flags.aliases[key].indexOf(c) === -1) {
     flags.aliases[key].push(c)
     newAliases[c] = true
   }
}

Which is not makes check of the length of an x, so single char became a camelCase so I added such check.

@bcoe
Copy link
Member

bcoe commented Nov 8, 2018

@coderaiser thank you for the contribution, sorry for the slow review.

@bcoe bcoe merged commit ee56e31 into yargs:master Nov 9, 2018
@coderaiser coderaiser deleted the fix/one-char-alias branch November 9, 2018 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants