Conversation
… exception if help() enabled
JaKXz
left a comment
There was a problem hiding this comment.
LGTM, my questions are more out of curiousity than blockers.
| counter++ | ||
| }) | ||
| .help() | ||
| y.parse(['foo'], function () {}) |
There was a problem hiding this comment.
related but tangential question: should the fn passed to parse be optional? i.e. if no fn is passed in, use a noop?
There was a problem hiding this comment.
It is optional, but specifying something prevents yargs from outputting to stdin (my possibly limited understanding of how it works).
There was a problem hiding this comment.
@JaKXz, @scriptdaemon is correct; if you provide a function, we assume that you want to hook into output -- rather than the output of parse being printed to stdout.
This is useful for chat-bots, which is @scriptdaemon use-case.
| it('allows command handler to be invoked repeatedly when help is enabled', function (done) { | ||
| var counter = 0 | ||
| var y = yargs([]) | ||
| .command('foo', 'the foo command', {}, function (argv) { |
There was a problem hiding this comment.
I don't know the test code well enough, but, my preference would be a method that is spied on and then asserted that it's been called twice, possibly outside the second parse call.
What do you think?
There was a problem hiding this comment.
@JaKXz I like this idea ... but I also have yet to pull sinon into the codebase. I think pulling in a mocking framework is beyond the scope of this pull, but I do like the idea. a couple questions come to mind:
- is there something lighter-weight than sinon that's popular?
- I think we should probably pull in a stub/mock framework in the context of a larger test cleanup.
There was a problem hiding this comment.
@bcoe I'm a big fan of https://github.com/testdouble/testdouble.js/ - and yeah I think it'd do nicely in a larger cleanup.
There was a problem hiding this comment.
@JaKXz awesome, perhaps we could eyeball the test-suite sometime soon, and see how many places we're using ad-hock spies -- if we're doing it a bunch of times, I say let's try testdouble.js out.
… exception if help() enabled (#790)
there was a bug that caused an exception to be raised when
parse()was called multiple times on the same yargs instance ifhelp()is enabled.fixes #776