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

Default command invoked when calling .showHelp #1791

Closed
wesleytodd opened this issue Oct 30, 2020 · 2 comments · Fixed by #1823
Closed

Default command invoked when calling .showHelp #1791

wesleytodd opened this issue Oct 30, 2020 · 2 comments · Fixed by #1823
Labels

Comments

@wesleytodd
Copy link

const yargs = require('yargs')

yargs.command('$0', 'a default command', (yargs) => yargs, () => {
  console.log('default command!! why?')
})
yargs.showHelp((output) => {
  console.log(output)
})

The above application will also execute the default command even though we never called .argv or .parse. This seems like unexpected behavior to me and I could not find any docs on this. Is this intended for some reason I am unaware of?

@bcoe bcoe added the bug label Nov 2, 2020
@bcoe
Copy link
Member

bcoe commented Nov 2, 2020

@wesleytodd this definitely doesn't seem like intended behavior, thanks for the bug report.

@bcoe
Copy link
Member

bcoe commented Jan 9, 2021

@wesleytodd I believe I fixed this as part of my work in #1823

There's also now a helper await yargs.getHelp(), which you could use rather than the callback based approach. I'd love feedback, you can install via:

npm i yargs@next

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants