diff options
Diffstat (limited to 'utils/utils.go')
-rw-r--r-- | utils/utils.go | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/utils/utils.go b/utils/utils.go index eaa6c09a9..381ebc53e 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -22,36 +22,39 @@ func CheckErr(err error, s ...string) { func StopOnErr(err error, s ...string) { if err != nil { - if len(s) == 0 { - newMessage := cutUsageMessage(err.Error()) + doStopOnErr(err, s...) + os.Exit(-1) + } +} - // Printing an empty string results in a error with - // no message, no bueno. - if newMessage != "" { - jww.CRITICAL.Println(newMessage) - } - } else { - for _, message := range s { - message := cutUsageMessage(message) +func doStopOnErr(err error, s ...string) { + if len(s) == 0 { + newMessage := cutUsageMessage(err.Error()) + // Printing an empty string results in a error with + // no message, no bueno. + if newMessage != "" { + jww.CRITICAL.Println(newMessage) + } + } else { + for _, message := range s { + message := cutUsageMessage(message) - if message != "" { - jww.CRITICAL.Println(message) - } + if message != "" { + jww.CRITICAL.Println(message) } } - os.Exit(-1) } } // cutUsageMessage splits the incoming string on the beginning of the usage // message text. Anything in the first element of the returned slice, trimmed -// of its Unicode defined spaces, should be returned. The 2nd element of the +// of its Unicode defined spaces, should be returned. The 2nd element of the // slice will have the usage message that we wish to elide. // // This is done because Cobra already prints Hugo's usage message; not eliding -// would result in the usage output being printed twice, which leads to bug +// would result in the usage output being printed twice, which leads to bug // reports, more specifically: https://github.com/spf13/hugo/issues/374 func cutUsageMessage(s string) string { - pieces := strings.Split(s, "Usage of") + pieces := strings.Split(s, "Usage of") return strings.TrimSpace(pieces[0]) } |