cli icon indicating copy to clipboard operation
cli copied to clipboard

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

Open nkuba opened this issue 3 years ago • 0 comments

My urfave/cli version is

v2.11.1

Checklist

  • [x] Are you running the latest v2 release? The list of releases is here.
  • [x] Did you check the manual for your release? The v2 manual is here
  • [x] 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 https://github.com/urfave/cli/pull/1442

Run go version and paste its output here

go version go1.18.3 darwin/amd64

nkuba avatar Jul 26 '22 13:07 nkuba