-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Return explicit usage error #1305
Comments
Notes after digging somewhat: the most straightforward implementation would be changing This way the two could be used in conjunction for errors which should either exit with a code, print usage or both. |
Something like this: https://play.golang.org/p/jGF1iYuBl9z |
Functional error options are also a possibility: https://play.golang.org/p/HMkLILVU3FP. This has the benefit of only a single type representing all of the things you might want to do specially with user errors, though it dispenses with the interface implementation paradigm, and is arguably slightly less flexible with regard to things like multierror, though I expect you could also provide a convenience |
@flowchartsman This a a good idea. Would you like to submit a PR for this ? |
Sure, but I wouldn't mind a little buy-in before I do an implementation. I think probably the most "correct" way to do it would be to use |
@flowchartsman PR #1545 might help. Can you let me know if it is what you are looking for ? We cant change the interface{} to error but breaking some clients so we'd rather not |
Wont fix in v2. Will be superseded by #1662 in v3 |
Checklist
What problem does this solve?
I have a CLI app that has differing arg requirements based on a particular flag. Either it will be
cmd sub --all <first>
orcmd sub <first> <second> [etc]...
I can check for the arg length and return an error fine, but it would be nice to be able to do something likeThis way, certain errors will automatically print the command usage, while later errors can fail as normal.
The text was updated successfully, but these errors were encountered: