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
When using a flagset, errors are printed to stderr in addition to being returned by flag.Parse(). It is redundant, since the caller can print the error if desired. It also creates a small issue in a situation where multiple flagsets are used to parse a single command line.
I have a command line interface that provides a wrapper to multiple modules. The command line has its own flagset [1], and forward the flags it cannot parse to one of many packages where specific flagsets are defined [2, 3]. The issue is that the first call to Parse() detects the flags it doesn't know and prints an error to stderr directly. I would like to avoid printing this error. I ended up setting the output to os.DevNull around the call to Parse() to prevent displaying it to the user, but it feels like a hack [4].
When using a flagset, errors are printed to stderr in addition to being returned by flag.Parse(). It is redundant, since the caller can print the error if desired. It also creates a small issue in a situation where multiple flagsets are used to parse a single command line.
I have a command line interface that provides a wrapper to multiple modules. The command line has its own flagset [1], and forward the flags it cannot parse to one of many packages where specific flagsets are defined [2, 3]. The issue is that the first call to Parse() detects the flags it doesn't know and prints an error to stderr directly. I would like to avoid printing this error. I ended up setting the output to os.DevNull around the call to Parse() to prevent displaying it to the user, but it feels like a hack [4].
The culpric is here: https://github.com/golang/go/blob/master/src/flag/flag.go#L793
I suggest removing that line and only returning the error to the caller through the Error value.
I'm not aware of a different way to split a flagset across packages, but if there's one, I'm very interested :)
[1] https://github.com/mozilla/mig/blob/master/src/mig/client/cmd/main.go#L71-L77
[2] https://github.com/mozilla/mig/blob/master/src/mig/modules/file/paramscreator.go#L285-L305
[3] https://github.com/mozilla/mig/blob/master/src/mig/modules/netstat/paramscreator.go#L171-L178
[4] https://github.com/mozilla/mig/blob/master/src/mig/client/cmd/main.go#L124
The text was updated successfully, but these errors were encountered: