Cli: Misleading user error message when using flags

Created on 18 May 2018  路  13Comments  路  Source: urfave/cli

Hi,

As far as I understand, cli expect the root/global flags to be provided between the binary name and the subcommand name, and the command flags to be provided at the end:

binary-name [global options] command [command options] [arguments...]

As this pattern is not that common, it's easy for a new user to try to provide the root flags at the end of the command. In this case, he will be greeted with a rather unhelpful error message:

Incorrect Usage: flag provided but not defined: -host

Note that the message is the same when trying a flag that doesn't exist.

Would it be possible to get a more explanatory message in these cases ? I tried to make a workaround using OnUsageError but it's impractical for several reasons:

  • you have to match and parse the error message
  • it's not a simple error message rewrite, it's a different code path inside cli and you have to emulate some behavior like printing the help text manually
  • you have to plug this workaround in every single command
help wanted kinbug statuconfirmed statustale

All 13 comments

Agreed. This format is not globally recognized and goes against how most CLIs work, where global options are not position-sensitive. This is extremely confusing, especially for experienced CLI end users.

I understand that's going on here 馃憤 I would be happy to help someone with a pull request for this issue!

I definitely agree that what we want is to allow global flags to be specified at any position. I'd love to see a PR for that, or for the issue of the misleading error message, or both!

Thats not true, I think kubectl also has position sensitive global flags, so we're not the only ones.

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

Hey @MichaelMure & @thedoc31, this issue may have been fixed by our v2 release? Check it out and let me know what you think.

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@lynncyrin I'll see if the internal project using the framework has plans to upgrade to v2. Thanks for following up!

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

This issue is still waiting for someone to investigate if it's still a problem, and stand up a PR if so 馃檹

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

Closing this as it has become stale.

Was this page helpful?
0 / 5 - 0 ratings