close output file after write

This commit is contained in:
gutmet 2020-11-05 00:15:01 +01:00
parent 0f22ab3e39
commit b03a77d2b7

6
TDL.go
View File

@ -26,7 +26,7 @@ func checkUsage(debugFlag string, args []string) {
} }
} }
func outfile(infile string) io.Writer { func outfile(infile string) *os.File {
basename := path.Base(infile) basename := path.Base(infile)
extension := path.Ext(basename) extension := path.Ext(basename)
basename = strings.TrimSuffix(basename, extension) basename = strings.TrimSuffix(basename, extension)
@ -67,7 +67,9 @@ func main() {
if stdout { if stdout {
writer = os.Stdout writer = os.Stdout
} else { } else {
writer = outfile(filename) out := outfile(filename)
defer out.Close()
writer = out
} }
generator := NewStdGenerator(writer) generator := NewStdGenerator(writer)
generator.Generate(parsed) generator.Generate(parsed)