Improve main.go: log error to stderr, output to stdout

This commit is contained in:
Niklas Fasching 2018-12-18 23:46:41 +01:00
parent 941f3ea520
commit c26d39284c

View file

@ -2,6 +2,7 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
@ -15,11 +16,10 @@ import (
) )
func main() { func main() {
log.SetFlags(0) log := log.New(os.Stderr, "", 0)
log.SetOutput(os.Stdout)
if len(os.Args) < 3 { if len(os.Args) < 3 {
log.Println("USAGE: org FILE OUTPUT_FORMAT") log.Println("USAGE: org FILE OUTPUT_FORMAT")
log.Fatal("supported output formats: org, html, html-chroma") log.Fatal("Supported output formats: org, html, html-chroma")
} }
path := os.Args[1] path := os.Args[1]
bs, err := ioutil.ReadFile(path) bs, err := ioutil.ReadFile(path)
@ -43,7 +43,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Print(out) fmt.Fprint(os.Stdout, out)
} }
func highlightCodeBlock(source, lang string) string { func highlightCodeBlock(source, lang string) string {