Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

stephensearles
Copy link
Contributor

@stephensearles stephensearles commented Dec 23, 2016

Fixes issue #13 and nsqio/nsq#826

@@ -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:] {
Copy link
Contributor Author

@stephensearles stephensearles Dec 23, 2016

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.

Copy link
Owner

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()
Copy link
Contributor Author

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:] {
Copy link
Owner

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()
}
Copy link
Owner

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()
}

@stephensearles
Copy link
Contributor Author

Thanks for taking care of that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants