close output file after write

This commit is contained in:
gutmet 2020-11-05 00:15:01 +01:00
parent 0f22ab3e39
commit b03a77d2b7
1 changed files with 4 additions and 2 deletions

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)
extension := path.Ext(basename)
basename = strings.TrimSuffix(basename, extension)
@ -67,7 +67,9 @@ func main() {
if stdout {
writer = os.Stdout
} else {
writer = outfile(filename)
out := outfile(filename)
defer out.Close()
writer = out
}
generator := NewStdGenerator(writer)
generator.Generate(parsed)