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

GenericFlag doesn't work with Destination: type *Generic is pointer to interface, not interface #1441

Closed
3 tasks done
nkuba opened this issue Jul 26, 2022 · 0 comments · Fixed by #1442 or #1488
Closed
3 tasks done
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@nkuba
Copy link
Contributor

nkuba commented Jul 26, 2022

My urfave/cli version is

v2.11.1

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the Github guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

When I configure a GenericFlag with a Destination the code doesn't compile.

To reproduce

  1. In the https://github.com/urfave/cli repository, paste the code below into the flag_test.go file.
type genericType struct {
	s string
}

func (g *genericType) Set(value string) error {
	g.s = value
	return nil
}

func (g *genericType) String() string {
	return g.s
}

func TestParseDestinationGeneric(t *testing.T) {
	var dest *genericType
	_ = (&App{
		Flags: []Flag{
			&GenericFlag{
				Name:        "dest",
				Destination: dest,
			},
		},
		Action: func(ctx *Context) error {
			if dest.String() != "10,20" {
				t.Errorf("expected destination Generic 10,20")
			}
			return nil
		},
	}).Run([]string{"run", "--dest", "10,20"})
}
  1. Run go test . command.

Observed behavior

./flag_test.go:2187:18: cannot use dest (variable of type *genericType) as type *Generic in struct literal:
        *genericType does not implement *Generic (type *Generic is pointer to interface, not interface)

Expected behavior

The value should be set in the destination.

Want to fix this yourself?

Please see #1442

Run go version and paste its output here

go version go1.18.3 darwin/amd64
@nkuba nkuba added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Jul 26, 2022
nkuba added a commit to nkuba/cli that referenced this issue Jul 26, 2022
In this commit I added a DestinationPointer variable that should be set
if the `Destination` should be configured as a pointer for a specific
flag type. It is expected that Generic type which is an interface will
not be a pointer but a struct. Before this change the code compilation
was failing with `type *Generic is pointer to interface, not interface`.

See urfave#1441
dearchap pushed a commit to nkuba/cli that referenced this issue Oct 6, 2022
In this commit I added a DestinationPointer variable that should be set
if the `Destination` should be configured as a pointer for a specific
flag type. It is expected that Generic type which is an interface will
not be a pointer but a struct. Before this change the code compilation
was failing with `type *Generic is pointer to interface, not interface`.

See urfave#1441
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
1 participant