Skip to content

Commit

Permalink
refactor: use 'log' instead of 'fmt'
Browse files Browse the repository at this point in the history
  • Loading branch information
krakozaure committed Jun 4, 2023
1 parent 6c93edc commit 5c4518f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"log"
"os"
)

Expand Down Expand Up @@ -53,8 +54,7 @@ func initFlags() {
)

flag.Usage = func() {
fmt.Fprintf(
os.Stderr,
log.Printf(
`USAGE: %s [OPTIONS] INPUT
INPUT is a template file or '-' for stdin
Expand Down
5 changes: 3 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"strings"

Expand Down Expand Up @@ -43,7 +44,7 @@ func getFileVariables(file string) map[string]interface{} {

bytes, err := ioutil.ReadFile(file)
if err != nil {
fmt.Fprint(os.Stderr, fmt.Errorf("unable to read file\n%v\n", err))
log.Printf("unable to read file\n%v\n", err)
return vars
}

Expand All @@ -57,7 +58,7 @@ func getFileVariables(file string) map[string]interface{} {
err = fmt.Errorf("bad file type: %s", file)
}
if err != nil {
fmt.Fprint(os.Stderr, fmt.Errorf("unable to load data\n%v\n", err))
log.Printf("unable to load data\n%v\n", err)
}
return vars
}
Expand Down
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
)

func main() {
log.SetFlags(0)
log.SetPrefix(fmt.Sprintf("%s: ", os.Args[0]))

initFlags()
if flag.NArg() == 0 {
log.SetPrefix("")
flag.Usage()
os.Exit(2)
}
Expand All @@ -26,8 +30,7 @@ func main() {

output, err := executeTemplateFile(input)
if err != nil {
fmt.Fprintf(os.Stderr, "%v", err)
return
log.Fatal(err)
}
fmt.Print(output)
}

0 comments on commit 5c4518f

Please sign in to comment.