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

Coerce gets called twice for nested command positionals #1966

Closed
CupOfTea696 opened this issue Jun 13, 2021 · 1 comment
Closed

Coerce gets called twice for nested command positionals #1966

CupOfTea696 opened this issue Jun 13, 2021 · 1 comment

Comments

@CupOfTea696
Copy link
Contributor

Coerce gets called multiple times for nested command positional, this could cause issues when the arg type is converted.

Example Script:

import yargs from 'yargs'

const argv = yargs('rule add foo bar baz').showHelpOnFail(false).fail(msg => {
  console.error(`[ERR] ${msg}`)
  process.exit(1)
}).command('rule', '', yargs => {
  return yargs.command('add <name> <desc...>', '', yargs => {
    return yargs.positional('desc', {
      type: 'string',
      coerce: arg => {
        console.log(arg)

        return arg.join(' ')
      }
    })
  })
}).argv

// the parsed data is stored in argv.
console.log(argv)

Expected Output:

[ 'bar', 'baz' ]
{ _: [ 'rule', 'add' ], '$0': 't.js', name: 'foo', desc: 'bar baz' }

Actual Output:

[ 'bar', 'baz' ]
bar baz
[ERR] arg.join is not a function
@shadowspawn
Copy link
Member

This was fixed in #1978. Thanks @CupOfTea696 for report, and fix from @jly36963

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

No branches or pull requests

2 participants