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
Also pass yargs to the fail handler #613
Conversation
@mkawalec love it. 👍 |
@bcoe: Should I change something, or can we merge this? :) |
@mkawalec sorry for the slow turnaround! looks great, but could I perhaps get you to add a test? Partially because it would be neat to see how you plan on using this functionality 👍 |
I'll add the test early next week, thanks for the review. |
@mkawalec would love to land this, any news on that test :) |
@bcoe: I've added the test, but it fails. The reason for that is that the exception thrown in command handler is not caught and so |
@mkawalec when I have some time this weekend I'll take a look at the harness 👍 |
@mkawalec this weekend has quickly become this following weekend, for which I apologize; I haven't forgotten about this pull. |
No worries @bcoe, I know the pain well :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good! make the slight copy change, and get the test updated, and I'll land this ASAP.
`fn` is called with the failure message that would have been printed and the | ||
`Error` instance originally thrown, if any. | ||
`fn` is called with the failure message that would have been printed, the | ||
`Error` instance originally thrown and yargs state when the failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slight editing nit, let's change this to:
fn
is called with the failure message that would have been printed, the
Error
instance originally thrown, and the yargs instance when the failure occurred.
@@ -473,6 +473,31 @@ describe('usage tests', function () { | |||
r.logs.should.deep.equal(['foo']) | |||
r.should.have.property('exit').and.be.false | |||
}) | |||
|
|||
it('gives the ability to log a per-command error message if failure occurs in a command', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I finally had the time to debug this test for you, here's the code I pulled together:
it('is invoked with yargs instance as third argument', function () {
var r = checkUsage(function () {
return yargs('foo')
.command('foo', 'desc', {
bar: {
describe: 'bar command'
}
}, function (argv) {
throw new Error('blah')
})
.fail(function (message, error, yargs) {
yargs.showHelp()
})
.exitProcess(false)
.wrap(null)
.argv
})
r.errors[0].should.contain('bar command')
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I know it's tiny, I'll find a minute tomorrow to integrate it in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mkawalec awesome 👍
@bcoe please rereview :) |
This is needed to display a complete help message for a command that failed in a top-level
fail
handler