summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rr/cmd/root.go9
-rw-r--r--cmd/util/cprint.go6
-rw-r--r--cmd/util/exit.go11
3 files changed, 20 insertions, 6 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go
index 8d75f9cd..d6929473 100644
--- a/cmd/rr/cmd/root.go
+++ b/cmd/rr/cmd/root.go
@@ -63,8 +63,7 @@ var (
// This is called by main.main(). It only needs to happen once to the CLI.
func Execute() {
if err := CLI.Execute(); err != nil {
- util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
- os.Exit(1)
+ util.ExitWithError(err)
}
}
@@ -98,14 +97,12 @@ func init() {
if workDir != "" {
if err := os.Chdir(workDir); err != nil {
- util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
- os.Exit(1)
+ util.ExitWithError(err)
}
}
if err := Container.Init(cfg); err != nil {
- util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
- os.Exit(1)
+ util.ExitWithError(err)
}
// global watcher config
diff --git a/cmd/util/cprint.go b/cmd/util/cprint.go
index c549317d..1d4d8cd3 100644
--- a/cmd/util/cprint.go
+++ b/cmd/util/cprint.go
@@ -5,6 +5,7 @@ import (
"github.com/mgutz/ansi"
"regexp"
"strings"
+ "os"
)
var (
@@ -35,3 +36,8 @@ func Sprintf(format string, args ...interface{}) string {
return fmt.Sprintf(format, args...)
}
+
+// Panicf prints `<white+hb>color formatted message to STDERR</reset>`.
+func Panicf(format string, args ...interface{}) {
+ fmt.Fprint(os.Stderr, Sprintf(format, args...))
+}
diff --git a/cmd/util/exit.go b/cmd/util/exit.go
new file mode 100644
index 00000000..96fcbf3c
--- /dev/null
+++ b/cmd/util/exit.go
@@ -0,0 +1,11 @@
+package util
+
+import (
+ "os"
+)
+
+// ExitWithError prints error and exits with error code`.
+func ExitWithError(err error) {
+ Panicf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
+ os.Exit(1)
+}