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

Strict mode doesn't know about context variables [7.x] #791

Closed
scriptdaemon opened this issue Feb 21, 2017 · 1 comment
Closed

Strict mode doesn't know about context variables [7.x] #791

scriptdaemon opened this issue Feb 21, 2017 · 1 comment

Comments

@scriptdaemon
Copy link

scriptdaemon commented Feb 21, 2017

Discussion moved from #776.

When running code like so against the 7.x branch:

'use strict'

// Node packaged modules
const yargs = require('yargs')
const parser = yargs()
parser.command({
  command: '!ch', // config.get('cmd'),
  description: 'test desc', // config.get('description'),
  builder: yargs => {
    yargs.command('dice', '', () => {}, () => {
      console.log('dice')
    })
    yargs.command('uptime', '', () => {}, () => {
      console.log('uptime')
    })
    yargs.help()
    yargs.strict()
    yargs.version()
  }
})

parser.parse('!ch uptime', { 'test': 'test' }, (err, argv, output) => {
  if (err && !output) throw err
  if (output) {
    console.log(output)
  }
})

parser.parse('!ch dice', { 'test': 'test' }, (err, argv, output) => {
  if (err && !output) throw err
  if (output) {
    console.log(output)
  }
})

I get an error declaring "test" is an unknown argument:

kwilliams@KENLAPTOP:/mnt/c/Users/kwilliams/Documents/Projects/cheevobot$ node .
 !ch uptime

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Unknown argument: test
 !ch dice

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Unknown argument: test

In response to @bcoe:

It seems like to simplify this use-case though, we should add all keys provided in context to the list of known arguments?

That sounds like it should do the trick. In my use-case, the context variables are always something I know ahead of time (at least for now) and can thus account for by specifying option() for each of them directly, but in some cases the context might not be known ahead of time.

@scriptdaemon scriptdaemon changed the title Strict mode doesn't know about context variables Strict mode doesn't know about context variables [7.x] Feb 21, 2017
@bcoe
Copy link
Member

bcoe commented Feb 25, 2017

@scriptdaemon we've landed this to 7.x.

@bcoe bcoe closed this as completed Feb 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants