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

Also pass yargs to the fail handler #613

Merged
merged 3 commits into from Nov 13, 2016
Merged

Also pass yargs to the fail handler #613

merged 3 commits into from Nov 13, 2016

Conversation

mkawalec
Copy link
Contributor

This is needed to display a complete help message for a command that failed in a top-level fail handler

@bcoe
Copy link
Member

bcoe commented Aug 31, 2016

@mkawalec love it. 👍

@mkawalec
Copy link
Contributor Author

mkawalec commented Sep 8, 2016

@bcoe: Should I change something, or can we merge this? :)

@bcoe
Copy link
Member

bcoe commented Sep 8, 2016

@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 👍

@mkawalec
Copy link
Contributor Author

mkawalec commented Sep 16, 2016

I'll add the test early next week, thanks for the review.

@bcoe
Copy link
Member

bcoe commented Sep 25, 2016

@mkawalec would love to land this, any news on that test :)

@mkawalec
Copy link
Contributor Author

@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 fail is never called. However, in a program I have that uses yargs the fail handler is called if an exception is thrown in the command handler. Is this a problem with the test harness or my mistake somewhere?

@bcoe
Copy link
Member

bcoe commented Sep 30, 2016

@mkawalec when I have some time this weekend I'll take a look at the harness 👍

@bcoe
Copy link
Member

bcoe commented Oct 6, 2016

@mkawalec this weekend has quickly become this following weekend, for which I apologize; I haven't forgotten about this pull.

@mkawalec
Copy link
Contributor Author

No worries @bcoe, I know the pain well :)

Copy link
Member

@bcoe bcoe left a 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
Copy link
Member

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 () {
Copy link
Member

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')
      })

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkawalec awesome 👍

@mkawalec
Copy link
Contributor Author

@bcoe please rereview :)

@bcoe bcoe merged commit 21b74f9 into yargs:master Nov 13, 2016
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

Successfully merging this pull request may close these issues.

None yet

2 participants