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

UNKNOWN_OPTION could be optional #38

Closed
flipflopapp opened this issue Jan 23, 2017 · 9 comments
Closed

UNKNOWN_OPTION could be optional #38

flipflopapp opened this issue Jan 23, 2017 · 9 comments

Comments

@flipflopapp
Copy link

When I use an app that uses the npm module with mocha (and I want to pass some options to mocha and others to the module being tested), I see an UNKNOWN_OPTION error. For example, I want to pass --no-timeout to mocha.

@flipflopapp
Copy link
Author

It requires minor changes

https://github.com/flipflopapp/command-line-args

works for my usecase.

@75lb
Copy link
Owner

75lb commented Jan 24, 2017

ok, thanks - i had a look at what you did.. I'm considering solutions for handling unknown options but won't be discarding them, as in your case.

Closing as a near-duplicate of #25, which i'm working on as we speak.

@75lb 75lb closed this as completed Jan 24, 2017
@75lb
Copy link
Owner

75lb commented Jan 24, 2017

btw, is there any reason you can't create a definition for --no-timeout if it's an option your app accepts?

@75lb
Copy link
Owner

75lb commented Jan 28, 2017

i've almost finished implementing a new feature to allow unknown options.. could you send an example of how your app was failing with mocha please, so i can test it?

@flipflopapp
Copy link
Author

(oops late response - missed the mail notifications). I can create a --no-timeouts option in my app but I thought I would have to add options everytime I wanted to pass a new option to mocha. The command line looks like below,

$ mocha test/test-file.js --some_option_for_app --some_option_for_mocha

My nodejs app accepts some parameters from command line arguments. It was failing when it saw arguments that were meant for mocha. Please let me know if I can provide anymore information.

@75lb
Copy link
Owner

75lb commented Jan 28, 2017

ok, thanks for the example - i understand what you're doing now, thanks.

@75lb
Copy link
Owner

75lb commented Jan 28, 2017

with the new version of command-line-args, if you have this mocha script:

/* demonstrates use in a mocha test script */
const assert = require('assert')
const commandLineArgs = require('../')

const options = commandLineArgs({ name: 'value', type: Number }, { partial: true })

describe('Array', function () {
  describe('#indexOf()', function () {
    it('should return -1 when the value is not present', function () {
      assert.equal(options.value, [ 1, 2, 3 ].indexOf(4))
    })
  })
})

you can run the script with a command like this and it will not throw a UNKNOWN_OPTION error:

$ mocha --no-colors example/mocha.js --value -1


  Array
    #indexOf()
      ✓ should return -1 when the value is not present


  1 passing (7ms)

options will look like this:

{
  "value": -1,
  "_unknown": [
    "--no-colors",
    "example/mocha.js"
  ]
}

@75lb
Copy link
Owner

75lb commented Jan 28, 2017

i've released a beta version which implements this feature.. for details, see #25 and let me know your thoughts. Thanks!

@flipflopapp
Copy link
Author

Looks perfect. Thanks for the quick turnaround. Cheers

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