diff --git a/cmd/go-tr/main.go b/cmd/go-tr/main.go index ebc93fb..7c2e8a6 100644 --- a/cmd/go-tr/main.go +++ b/cmd/go-tr/main.go @@ -35,7 +35,7 @@ func getFlags() (int, string, string) { } func checkFlagsAreValid(source, target string) { - if source == "" || target == "" { + if source == "" { printUsage() os.Exit(1) } @@ -58,12 +58,16 @@ func safeTranspile(mode int, source, target string) { os.Exit(1) } defer in.Close() - // Create the Arduino sketch file. - os.Remove(target) - out, err := os.OpenFile(target, os.O_CREATE|os.O_RDWR|os.O_SYNC, 0666) - if err != nil { - fmt.Fprintf(os.Stderr, "Arduino sketch file [%s] could not be opened! %v", target, err) - os.Exit(1) + + out := os.Stdout + if target != "" { + // Create the Arduino sketch file. + os.Remove(target) + out, err = os.OpenFile(target, os.O_CREATE|os.O_RDWR|os.O_SYNC, 0666) + if err != nil { + fmt.Fprintf(os.Stderr, "Arduino sketch file [%s] could not be opened! %v", target, err) + os.Exit(1) + } } switch mode { case CPP_MODE: