You'll need to create a FlagSet instead and pass ContinueOnError as the error handling. If .Parse() returns an error call .PrintDefaults(), then print the error.
On Sun, Dec 8, 2019 at 4:00 AM Thomas Nyberg <tomnyb...@gmail.com> wrote: > > Hello, > > Given the following file `flag_example.go`: > > package main > > import "flag" > > func main() { > flagName := flag.String("flagName", "flagValue", "Help message.") > flag.Parse() > _ = flagName > } > > If I execute it with a bad flag passed I see the following: > > $ ./flag_example -flagName > flag needs an argument: -flagName > Usage of ./flag_example: > -flagName string > Help message. (default "flagValue") > > What I would like to see is something like the following: > > $ ./flag_example -flagName > Usage of ./flag_example: > -flagName string > Help message. (default "flagValue") > > flag needs an argument: -flagName > > In other words, I would like to move the error to the end. Is there an easy > way to achieve this? I know about changing Usage, but that doesn't seem to > affect this specific issue. Thanks for any help! > > Cheers, > Thomas > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/CADDBb4JFEEhQcHVF2csObgCdEgQaGGQYJntYoiWYYOjko8tEzw%40mail.gmail.com. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAK4xykV-PSQTcfr_Jvq12nnSQ5rZ48nHepptVewVBvgfUwsdYw%40mail.gmail.com.