You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ go run minimal.go -ggg
flag provided but not defined: -ggg
Usage of /home/anatoli/.cache/go-build/8d/8dae0dadd55b6ae9e6d4bca4d6c85e20970b537337a98a5006eaeef926f92b5f-d/minimal:
exit status 2
Usage is the function called when an error occurs while parsing flags.
...
What happens after Usage is called depends on the ErrorHandling setting; for the command line, this defaults to ExitOnError, which exits the program after calling Usage.
ErrorHandling only affects what happens after Usage.
Closing as working as intended.
Go version
1.24
Output of
go env
in your module/workspace:What did you do?
Minimal
flags
example (https://go.dev/play/p/r6dDUoerjTI):Running this example with invalid flag always prints usage that is impossible to turn off regardless of error handling strategy https://pkg.go.dev/flag#ErrorHandling
What did you see happen?
$ go run minimal.go -ggg flag provided but not defined: -ggg Usage of /home/anatoli/.cache/go-build/8d/8dae0dadd55b6ae9e6d4bca4d6c85e20970b537337a98a5006eaeef926f92b5f-d/minimal: exit status 2
The problem is in
failf
function https://cs.opensource.google/go/go/+/refs/tags/go1.24.2:src/flag/flag.go;l=1060 that outputs the usage two levels belowParse
where it should be handled.Parse
-->parseOne
-->failf
-->usage
The similar report #63977
What did you expect to see?
At least some way to suppress usage message in errors.
Right now the only way to do this is to completely turn off all
flag
output and handle it all manually.The text was updated successfully, but these errors were encountered: