Add DestinationPointer for flags generator

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 https://github.com/urfave/cli/issues/1441
This commit is contained in:
Jakub Nowakowski
2022-07-26 16:13:05 +02:00
committed by Naveen Gogineni
parent b68db8d010
commit 891ffb017b
4 changed files with 166 additions and 2 deletions

View File

@@ -17,7 +17,11 @@ type {{.TypeName}} struct {
HasBeenSet bool
Value {{if .ValuePointer}}*{{end}}{{.GoType}}
<<<<<<< HEAD:cmd/urfave-cli-genflags/generated.gotmpl
Destination {{if .NoDestinationPointer}}{{else}}*{{end}}{{.GoType}}
=======
Destination {{if .DestinationPointer}}*{{end}}{{.GoType}}
>>>>>>> Add DestinationPointer for flags generator:internal/genflags/generated.gotmpl
Aliases []string
EnvVars []string

View File

@@ -80,8 +80,9 @@ func genFlagType() *main.FlagType {
Type: "bool",
},
},
TypeName: "YeOldeBlerfFlag",
ValuePointer: true,
TypeName: "YeOldeBlerfFlag",
ValuePointer: true,
DestinationPointer: true,
},
}
}
@@ -115,6 +116,21 @@ func TestFlagType_ValuePointer(t *testing.T) {
}
}
func TestFlagType_DestinationPointer(t *testing.T) {
ft := genFlagType()
if !ft.DestinationPointer() {
t.Errorf("expected DestinationPointer to be true")
return
}
ft.Config = nil
if ft.DestinationPointer() {
t.Errorf("expected DestinationPointer to be false")
}
}
func TestFlagType_GenerateFmtStringerInterface(t *testing.T) {
ft := genFlagType()