Skip to content

Commit 15491d6

Browse files
committed
Fix: dont generate pointer for dest for Generic flag
1 parent 6124f3a commit 15491d6

File tree

5 files changed

+64
-46
lines changed

5 files changed

+64
-46
lines changed

cmd/urfave-cli-genflags/generated.gotmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type {{.TypeName}} struct {
1717
HasBeenSet bool
1818

1919
Value {{if .ValuePointer}}*{{end}}{{.GoType}}
20-
Destination *{{.GoType}}
20+
Destination {{if .NoDestinationPointer}}{{else}}*{{end}}{{.GoType}}
2121

2222
Aliases []string
2323
EnvVars []string

cmd/urfave-cli-genflags/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,11 @@ func (gfs *Spec) SortedFlagTypes() []*FlagType {
223223
}
224224

225225
type FlagTypeConfig struct {
226-
SkipInterfaces []string `yaml:"skip_interfaces"`
227-
StructFields []*FlagStructField `yaml:"struct_fields"`
228-
TypeName string `yaml:"type_name"`
229-
ValuePointer bool `yaml:"value_pointer"`
226+
SkipInterfaces []string `yaml:"skip_interfaces"`
227+
StructFields []*FlagStructField `yaml:"struct_fields"`
228+
TypeName string `yaml:"type_name"`
229+
ValuePointer bool `yaml:"value_pointer"`
230+
NoDestinationPointer bool `yaml:"no_destination_pointer"`
230231
}
231232

232233
type FlagStructField struct {
@@ -256,6 +257,14 @@ func (ft *FlagType) ValuePointer() bool {
256257
return ft.Config.ValuePointer
257258
}
258259

260+
func (ft *FlagType) NoDestinationPointer() bool {
261+
if ft.Config == nil {
262+
return false
263+
}
264+
265+
return ft.Config.NoDestinationPointer
266+
}
267+
259268
func (ft *FlagType) TypeName() string {
260269
return TypeName(ft.GoType, ft.Config)
261270
}

flag-spec.yaml

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,71 @@
55
flag_types:
66
bool:
77
struct_fields:
8-
- { name: Count, type: int, pointer: true }
9-
float64: {}
10-
int64:
11-
struct_fields:
12-
- { name: Base, type: int }
13-
int:
14-
struct_fields:
15-
- { name: Base, type: int }
16-
time.Duration: {}
17-
uint64:
18-
struct_fields:
19-
- { name: Base, type: int }
20-
uint:
21-
struct_fields:
22-
- { name: Base, type: int }
23-
24-
string:
25-
struct_fields:
26-
- { name: TakesFile, type: bool }
27-
Generic:
28-
struct_fields:
29-
- { name: TakesFile, type: bool }
30-
Path:
31-
struct_fields:
32-
- { name: TakesFile, type: bool }
33-
8+
- name: Count
9+
type: int
10+
pointer: true
11+
float64:
3412
Float64Slice:
3513
value_pointer: true
3614
skip_interfaces:
3715
- fmt.Stringer
38-
Int64Slice:
39-
value_pointer: true
40-
skip_interfaces:
41-
- fmt.Stringer
16+
int:
17+
struct_fields:
18+
- name: Base
19+
type: int
4220
IntSlice:
4321
value_pointer: true
4422
skip_interfaces:
4523
- fmt.Stringer
46-
StringSlice:
24+
int64:
25+
struct_fields:
26+
- name: Base
27+
type: int
28+
Int64Slice:
4729
value_pointer: true
4830
skip_interfaces:
4931
- fmt.Stringer
32+
uint:
5033
struct_fields:
51-
- { name: TakesFile, type: bool }
52-
Timestamp:
53-
value_pointer: true
54-
struct_fields:
55-
- { name: Layout, type: string }
56-
- { name: Timezone, type: "*time.Location" }
57-
34+
- name: Base
35+
type: int
5836
UintSlice:
5937
value_pointer: true
6038
skip_interfaces:
6139
- fmt.Stringer
40+
uint64:
41+
struct_fields:
42+
- name: Base
43+
type: int
6244
Uint64Slice:
45+
value_pointer: true
46+
skip_interfaces:
47+
- fmt.Stringer
48+
string:
49+
struct_fields:
50+
- name: TakesFile
51+
type: bool
52+
StringSlice:
6353
value_pointer: true
6454
skip_interfaces:
6555
- fmt.Stringer
66-
56+
struct_fields:
57+
- name: TakesFile
58+
type: bool
59+
time.Duration:
60+
Timestamp:
61+
value_pointer: true
62+
struct_fields:
63+
- name: Layout
64+
type: string
65+
- name: Timezone
66+
type: "*time.Location"
67+
Generic:
68+
no_destination_pointer: true
69+
struct_fields:
70+
- name: TakesFile
71+
type: bool
72+
Path:
73+
struct_fields:
74+
- name: TakesFile
75+
type: bool

godoc-current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ type GenericFlag struct {
10851085
HasBeenSet bool
10861086

10871087
Value Generic
1088-
Destination *Generic
1088+
Destination Generic
10891089

10901090
Aliases []string
10911091
EnvVars []string

zz_generated.flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type GenericFlag struct {
5858
HasBeenSet bool
5959

6060
Value Generic
61-
Destination *Generic
61+
Destination Generic
6262

6363
Aliases []string
6464
EnvVars []string

0 commit comments

Comments
 (0)