Removed usage of log

This commit is contained in:
mfarah 2015-10-06 16:39:19 +11:00
parent 1d5fbd5ad0
commit 955ecc2547
2 changed files with 12 additions and 9 deletions

View File

@ -2,7 +2,6 @@ package main
import (
// "fmt"
"log"
"strconv"
)
@ -48,7 +47,7 @@ func recurse(value interface{}, head string, tail []string) interface{} {
}
index, err := strconv.ParseInt(head, 10, 64)
if err != nil {
log.Fatalf("Error accessing array: %v", err)
die("Error accessing array: %v", err)
}
return readArray(value.([]interface{}), index, tail)
case map[interface{}]interface{}:

18
yaml.go
View File

@ -5,7 +5,6 @@ import (
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
"strconv"
"strings"
@ -68,7 +67,7 @@ func readProperty(cmd *cobra.Command, args []string) {
func writeProperty(cmd *cobra.Command, args []string) {
if len(args) < 3 {
log.Fatalf("Must provide <filename> <path_to_update> <value>")
die("Must provide <filename> <path_to_update> <value>")
}
var parsedData map[interface{}]interface{}
@ -108,7 +107,7 @@ func printYaml(context interface{}) {
func yamlToString(context interface{}) string {
out, err := yaml.Marshal(context)
if err != nil {
log.Fatalf("error printing yaml: %v", err)
die("error printing yaml: %v", err)
}
outStr := string(out)
// trim the trailing new line as it's easier for a script to add
@ -121,7 +120,7 @@ func yamlToString(context interface{}) string {
func readYaml(args []string, parsedData *map[interface{}]interface{}) {
if len(args) == 0 {
log.Fatalf("Must provide filename")
die("Must provide filename")
}
var rawData []byte
@ -133,14 +132,14 @@ func readYaml(args []string, parsedData *map[interface{}]interface{}) {
err := yaml.Unmarshal([]byte(rawData), &parsedData)
if err != nil {
log.Fatalf("error: %v", err)
die("error: %v", err)
}
}
func readStdin() []byte {
bytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
log.Fatalf("error reading stdin", err)
die("error reading stdin", err)
}
return bytes
}
@ -148,7 +147,12 @@ func readStdin() []byte {
func readFile(filename string) []byte {
var rawData, readError = ioutil.ReadFile(filename)
if readError != nil {
log.Fatalf("error: %v", readError)
die("error: %v", readError)
}
return rawData
}
func die(message ...interface{}) {
fmt.Println(message)
os.Exit(1)
}