-
Notifications
You must be signed in to change notification settings - Fork 16
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
using struct value as the final default. fixes #13 #14
Conversation
@@ -289,11 +286,12 @@ func coerce(v interface{}, opt interface{}, arg string) (interface{}, error) { | |||
return nil, fmt.Errorf("invalid value type %T", v) | |||
} | |||
|
|||
func hasArg(s string) bool { | |||
for _, arg := range os.Args[1:] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this was ever actually working in most tests. I think they passed because they were using flagSet defaults instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Visit
existed in earlier version of go 🤷♂️
v = getter.Get() | ||
} | ||
// value | ||
v = val.Field(i).Interface() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the primary change
@@ -289,11 +286,12 @@ func coerce(v interface{}, opt interface{}, arg string) (interface{}, error) { | |||
return nil, fmt.Errorf("invalid value type %T", v) | |||
} | |||
|
|||
func hasArg(s string) bool { | |||
for _, arg := range os.Args[1:] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Visit
existed in earlier version of go 🤷♂️
// flag value | ||
if getter, ok := flagInst.Value.(flag.Getter); ok { | ||
v = getter.Get() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this case is still required e.g. https://github.com/nsqio/nsq/blob/master/apps/nsqd/nsqd.go#L41
Perhaps this should be:
if getter, ok := flagInst.Value.(flag.Getter); ok {
v = getter.Get()
} else {
v = val.Field(i).Interface()
}
Thanks for taking care of that! |
Fixes issue #13 and nsqio/nsq#826