@@ -45,28 +45,31 @@ func run() error {
45
45
astFiles = append (astFiles , astFile )
46
46
}
47
47
48
+ // TypeSpec case for structs and type alias
48
49
loopSpecs (astFiles , func (spec ast.Spec ) {
49
50
pos := fset .Position (spec .Pos ())
50
- switch s := spec .(type ) {
51
- // TypeSpec case for structs and type alias
52
- case * ast.TypeSpec :
53
- out , err := handleTypeSpec (s , pos , enums )
54
- if err != nil {
55
- break
56
- }
57
-
58
- _ , _ = fmt .Printf (out )
51
+ s , ok := spec .(* ast.TypeSpec )
52
+ if ! ok {
53
+ return
59
54
}
55
+ out , err := handleTypeSpec (s , pos , enums )
56
+ if err != nil {
57
+ return
58
+ }
59
+
60
+ _ , _ = fmt .Printf (out )
60
61
})
61
62
63
+ // ValueSpec case for loading type alias values into the enum map
62
64
loopSpecs (astFiles , func (spec ast.Spec ) {
63
- switch s := spec .(type ) {
64
- // ValueSpec case for const "enums"
65
- case * ast.ValueSpec :
66
- handleValueSpec (s , enums )
65
+ s , ok := spec .(* ast.ValueSpec )
66
+ if ! ok {
67
+ return
67
68
}
69
+ handleValueSpec (s , enums )
68
70
})
69
71
72
+ // write each type alias declaration with possible values
70
73
for _ , v := range enums {
71
74
_ , _ = fmt .Printf ("%s\n " , v )
72
75
}
0 commit comments