-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
flag: no way to access name of flag.FlagSet #21888
Comments
type FlagSet struct {
*flag.FlagSet
Name string
}
func NewFlagSet(name string, errorHandling flag.ErrorHandling) *FlagSet {
return &FlagSet{flag.NewFlagSet(name, errorHandling), name}
} edit: premature click. |
@cznic: that's a reasonable alternative, but it breaks interoperability with the existing |
Change https://golang.org/cl/70391 mentions this issue: |
@ianlancetaylor Would adding the proposal flag on this help in getting a decision made? |
Hard to say. |
Related: #17628 |
Per discussion with proposal review, OK. |
@bontibon I think so. |
Yes, that's OK too. |
For future reference: is it typical to submit a patch to Gerrit that implements a proposal before the proposal is accepted? I was kinda hoping to do this one myself and was surprised to see someone else submit a patch preemptively. |
It is not typical, but also not forbidden. Sorry you didn't get a chance at it. |
flag.NewFlagSet
takes aname
parameter in its constructor, but does not provide a way to access this name afterward. I suggest either exporting theName
field offlag.FlagSet
or adding aName()
method. Happy to implement either of these if they are approved.Motivation:
I wrote a small package that implements CLI subcommands via
flag.FlagSet
-based lookup trees, where the name of theflag.FlagSet
is the name of the subcommand. Since it is currently impossible to access the name of aflag.FlagSet
, I resorted to usingunsafe.Pointer
to read thename
field. Obviously I would like to replace this with something more robust as soon as possible.I acknowledge that this isn't a common problem, but I think the proposal would be reasonable even without a motivating example. The name of a
flag.FlagSet
is one of its defining properties, so it makes sense for it to have an associated getter. (The same argument could be made forerrorHandling
, I suppose.)The text was updated successfully, but these errors were encountered: