Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-10-05 21:26:49 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2015-10-05 21:26:49 +0300
commitb25ba8b095a75da78a129d494c3579f427a2d4a7 (patch)
treeecdfd638673344bae0daf95154feeee742b67237 /utils
parentb9aaa0079b95ed29ad2f36ebf077a61cb11fc7cb (diff)
Let Cobra do the usage error logging
Fixes #1472
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.go18
-rw-r--r--utils/utils_test.go26
2 files changed, 1 insertions, 43 deletions
diff --git a/utils/utils.go b/utils/utils.go
index ea89ec745..7bb9e5852 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -2,7 +2,6 @@ package utils
import (
"os"
- "strings"
jww "github.com/spf13/jwalterweatherman"
)
@@ -23,7 +22,7 @@ func CheckErr(err error, s ...string) {
func StopOnErr(err error, s ...string) {
if err != nil {
if len(s) == 0 {
- newMessage := cutUsageMessage(err.Error())
+ newMessage := err.Error()
// Printing an empty string results in a error with
// no message, no bueno.
@@ -32,8 +31,6 @@ func StopOnErr(err error, s ...string) {
}
} else {
for _, message := range s {
- message := cutUsageMessage(message)
-
if message != "" {
jww.CRITICAL.Println(message)
}
@@ -42,16 +39,3 @@ func StopOnErr(err error, s ...string) {
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
-// 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
-// reports, more specifically: https://github.com/spf13/hugo/issues/374
-func cutUsageMessage(s string) string {
- pieces := strings.Split(s, "Usage of")
- return strings.TrimSpace(pieces[0])
-}
diff --git a/utils/utils_test.go b/utils/utils_test.go
deleted file mode 100644
index 4ec2a4eec..000000000
--- a/utils/utils_test.go
+++ /dev/null
@@ -1,26 +0,0 @@
-package utils
-
-import (
- "testing"
-)
-
-func TestCutUsageMessage(t *testing.T) {
- tests := []struct {
- message string
- cutMessage string
- }{
- {"", ""},
- {" Usage of hugo: \n -b, --baseURL=...", ""},
- {"Some error Usage of hugo: \n", "Some error"},
- {"Usage of hugo: \n -b --baseU", ""},
- {"CRITICAL error for usage of hugo ", "CRITICAL error for usage of hugo"},
- {"Invalid short flag a in -abcde", "Invalid short flag a in -abcde"},
- }
-
- for _, test := range tests {
- message := cutUsageMessage(test.message)
- if message != test.cutMessage {
- t.Errorf("Expected %#v, got %#v", test.cutMessage, message)
- }
- }
-}