@@ -87,7 +87,7 @@ func generateInterface(folder, outputFile, pkgName, structName, ifName, outputTe
8787
8888 funcs := make ([]string , 0 )
8989 for _ , file := range appPkg .Files {
90- // fmt .Printf("parsing %s\n", fset.File(file.Pos()).Name())
90+ log .Printf ("parsing %s\n " , fset .File (file .Pos ()).Name ())
9191 if fset .File (file .Pos ()).Name () == outputFile {
9292 continue
9393 }
@@ -120,14 +120,15 @@ func generateInterface(folder, outputFile, pkgName, structName, ifName, outputTe
120120 log .Panic (err )
121121 }
122122 os .Remove (outputFile )
123- formatted , err := imports .Process (outputFile , out .Bytes (), & imports.Options {})
123+ formatted , err := imports .Process (outputFile , out .Bytes (), & imports.Options {Comments : true })
124124 if err != nil {
125125 log .Panic (err )
126126 }
127127 err = ioutil .WriteFile (outputFile , formatted , 0644 )
128128 if err != nil {
129129 log .Panic (err )
130130 }
131+ log .Printf ("Written %s successfully" , outputFile )
131132}
132133
133134func main () {
@@ -139,6 +140,15 @@ func main() {
139140 Use : "struct2interface" ,
140141 Short : "Extract an interface from a Golang struct" ,
141142 Run : func (cmd * cobra.Command , args []string ) {
143+
144+ if outputTemplateFile != "" {
145+ d , err := ioutil .ReadFile (outputTemplateFile )
146+ if err != nil {
147+ log .Panic (err )
148+ }
149+ outputTemplate = string (d )
150+ }
151+
142152 generateInterface (folder , outputFile , pkgName , structName , ifName , outputTemplate )
143153 },
144154 }
@@ -160,12 +170,4 @@ func main() {
160170 os .Exit (1 )
161171 }
162172
163- if outputTemplateFile != "" {
164- d , err := ioutil .ReadFile (outputTemplateFile )
165- if err != nil {
166- log .Panic (err )
167- }
168- outputTemplate = string (d )
169- }
170-
171173}
0 commit comments