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

actively calling showHelp shows different output then help on fail does #1853

Closed
foxriver76 opened this issue Jan 16, 2021 · 5 comments · Fixed by #1865
Closed

actively calling showHelp shows different output then help on fail does #1853

foxriver76 opened this issue Jan 16, 2021 · 5 comments · Fixed by #1865
Labels

Comments

@foxriver76
Copy link

foxriver76 commented Jan 16, 2021

In our code we use commands and "subcommands", calling our tool via iobroker object will result in our code processing the command and then calling yargs.showHelp(), the generated output looks like:

iob object
Unknown command "object undefined"!
iobroker object

Object management

Commands:
  iobroker get <id>                                     Get object specified by id
...
...
...

I would expect, that it shows iobroker object get <id> and not iobroker get <id> as it is done when I call iobroker object --help:

moritz@moritz-ThinkPad-E470:~/workspaces/ioBroker.js-controller$ iob object --help
iobroker object

Object management

Commands:
  iobroker object get <id>                                     Get object specified by id
...
...
...

Why is there a difference, is this intended? If yes, how can I achieve the desired output via showHelp()?

You can find the relevant code here: https://github.com/ioBroker/ioBroker.js-controller/blob/12a235299be58d7bb4592d71d61478afe9f1797b/lib/setup.js#L34-L370

@bcoe bcoe added the bug label Jan 18, 2021
@bcoe
Copy link
Member

bcoe commented Jan 18, 2021

@foxriver76 in the version of yargs on master (not yet released to npm), we've added a method await getHelp() which will return a help string to you.

Could you try this out, and see if it gives you appropriate output? my hope was that this would make the use case of outputting help programmatically easier. I did also fix some bugs with showHelp() in the process, so I'd try both.

@foxriver76
Copy link
Author

Hey, thanks for your reply.

I've installed 17.0.0-candidate.0 from GitHub, unfortunately this does not change the behavior. Also

const test = await yargs.getHelp();
console.log(test);

is printing the output w/o the desired object keyword. There has to be a difference between calling getHelp (and showHelp) and giving the output via --help flag. As mentioend above, using --help flag outputs the help correctly.

bcoe added a commit that referenced this issue Feb 15, 2021
Prior to this fix, we only cached the help message for commands
when using async commands. I believe we always want to cache the
help message for cases like #1853.

Fixes #1853
bcoe added a commit that referenced this issue Feb 15, 2021
Prior to this fix, we only cached the help message for commands
when using async commands. I believe we always want to cache the
help message for cases like #1853.

Fixes #1853
@bcoe
Copy link
Member

bcoe commented Feb 15, 2021

@foxriver76 could you please try npm i [email protected], I believe I figured out a fix.

@foxriver76
Copy link
Author

Sorry for the delayed reply, unfortunately, the inconsistencies remain the same.

@foxriver76
Copy link
Author

foxriver76 commented Apr 25, 2021

For me this is not fixed as stated, however I am unable to reopen. @bcoe

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