cli: Misleading user error message when using flags
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
cliand you have to emulate some behavior like printing the help text manually - you have to plug this workaround in every single command
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 17 (9 by maintainers)
@lynncyrin I’ll see if the internal project using the framework has plans to upgrade to v2. Thanks for following up!
Thats not true, I think kubectl also has position sensitive global flags, so we’re not the only ones.
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!
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.