From 15491d6f91e252cf9fc4c28163eb6ffea91e50a5 Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Sat, 10 Sep 2022 18:03:25 -0400 Subject: [PATCH] Fix: dont generate pointer for dest for Generic flag --- cmd/urfave-cli-genflags/generated.gotmpl | 2 +- cmd/urfave-cli-genflags/main.go | 17 +++-- flag-spec.yaml | 87 +++++++++++++----------- godoc-current.txt | 2 +- zz_generated.flags.go | 2 +- 5 files changed, 64 insertions(+), 46 deletions(-) diff --git a/cmd/urfave-cli-genflags/generated.gotmpl b/cmd/urfave-cli-genflags/generated.gotmpl index ed58b4f042..91312f8d5a 100644 --- a/cmd/urfave-cli-genflags/generated.gotmpl +++ b/cmd/urfave-cli-genflags/generated.gotmpl @@ -17,7 +17,7 @@ type {{.TypeName}} struct { HasBeenSet bool Value {{if .ValuePointer}}*{{end}}{{.GoType}} - Destination *{{.GoType}} + Destination {{if .NoDestinationPointer}}{{else}}*{{end}}{{.GoType}} Aliases []string EnvVars []string diff --git a/cmd/urfave-cli-genflags/main.go b/cmd/urfave-cli-genflags/main.go index c754147bea..1b0fe532a6 100644 --- a/cmd/urfave-cli-genflags/main.go +++ b/cmd/urfave-cli-genflags/main.go @@ -223,10 +223,11 @@ func (gfs *Spec) SortedFlagTypes() []*FlagType { } type FlagTypeConfig struct { - SkipInterfaces []string `yaml:"skip_interfaces"` - StructFields []*FlagStructField `yaml:"struct_fields"` - TypeName string `yaml:"type_name"` - ValuePointer bool `yaml:"value_pointer"` + SkipInterfaces []string `yaml:"skip_interfaces"` + StructFields []*FlagStructField `yaml:"struct_fields"` + TypeName string `yaml:"type_name"` + ValuePointer bool `yaml:"value_pointer"` + NoDestinationPointer bool `yaml:"no_destination_pointer"` } type FlagStructField struct { @@ -256,6 +257,14 @@ func (ft *FlagType) ValuePointer() bool { return ft.Config.ValuePointer } +func (ft *FlagType) NoDestinationPointer() bool { + if ft.Config == nil { + return false + } + + return ft.Config.NoDestinationPointer +} + func (ft *FlagType) TypeName() string { return TypeName(ft.GoType, ft.Config) } diff --git a/flag-spec.yaml b/flag-spec.yaml index ffd5cc2584..72e3c15d6a 100644 --- a/flag-spec.yaml +++ b/flag-spec.yaml @@ -5,62 +5,71 @@ flag_types: bool: struct_fields: - - { name: Count, type: int, pointer: true } - float64: {} - int64: - struct_fields: - - { name: Base, type: int } - int: - struct_fields: - - { name: Base, type: int } - time.Duration: {} - uint64: - struct_fields: - - { name: Base, type: int } - uint: - struct_fields: - - { name: Base, type: int } - - string: - struct_fields: - - { name: TakesFile, type: bool } - Generic: - struct_fields: - - { name: TakesFile, type: bool } - Path: - struct_fields: - - { name: TakesFile, type: bool } - + - name: Count + type: int + pointer: true + float64: Float64Slice: value_pointer: true skip_interfaces: - fmt.Stringer - Int64Slice: - value_pointer: true - skip_interfaces: - - fmt.Stringer + int: + struct_fields: + - name: Base + type: int IntSlice: value_pointer: true skip_interfaces: - fmt.Stringer - StringSlice: + int64: + struct_fields: + - name: Base + type: int + Int64Slice: value_pointer: true skip_interfaces: - fmt.Stringer + uint: struct_fields: - - { name: TakesFile, type: bool } - Timestamp: - value_pointer: true - struct_fields: - - { name: Layout, type: string } - - { name: Timezone, type: "*time.Location" } - + - name: Base + type: int UintSlice: value_pointer: true skip_interfaces: - fmt.Stringer + uint64: + struct_fields: + - name: Base + type: int Uint64Slice: + value_pointer: true + skip_interfaces: + - fmt.Stringer + string: + struct_fields: + - name: TakesFile + type: bool + StringSlice: value_pointer: true skip_interfaces: - fmt.Stringer - + struct_fields: + - name: TakesFile + type: bool + time.Duration: + Timestamp: + value_pointer: true + struct_fields: + - name: Layout + type: string + - name: Timezone + type: "*time.Location" + Generic: + no_destination_pointer: true + struct_fields: + - name: TakesFile + type: bool + Path: + struct_fields: + - name: TakesFile + type: bool diff --git a/godoc-current.txt b/godoc-current.txt index 7102c25e51..fbeeb5fb8b 100644 --- a/godoc-current.txt +++ b/godoc-current.txt @@ -1085,7 +1085,7 @@ type GenericFlag struct { HasBeenSet bool Value Generic - Destination *Generic + Destination Generic Aliases []string EnvVars []string diff --git a/zz_generated.flags.go b/zz_generated.flags.go index 4799c920df..034ef35dad 100644 --- a/zz_generated.flags.go +++ b/zz_generated.flags.go @@ -58,7 +58,7 @@ type GenericFlag struct { HasBeenSet bool Value Generic - Destination *Generic + Destination Generic Aliases []string EnvVars []string