add helpers: 'er', 'Er' and 'WrStringAndCheck', use 'io.StringWriter'

This commit is contained in:
umarcor 2019-06-07 19:17:26 +02:00
parent 44c8ae4518
commit 7b62ee10c2

View file

@ -19,6 +19,7 @@ package cobra
import (
"fmt"
"io"
"os"
"reflect"
"strconv"
"strings"
@ -205,3 +206,18 @@ func stringInSlice(a string, list []string) bool {
}
return false
}
func er(msg interface{}) {
if msg != nil {
fmt.Println("Error:", msg)
os.Exit(1)
}
}
// Er prints the msg and exits with error code 1, unless the msg is nil
func Er(msg interface{}) { er(msg) }
func WrStringAndCheck(b io.StringWriter, s string) {
_, err := b.WriteString(s)
er(err)
}