Skip to content

Commit 5485705

Browse files
committed
Add helper functions to the feedback package for CLI output
The log is used for output during the sync process, but that format is not necessary when the tool is being used directly by a maintainer. These functions will ensure that all the warning and error output displayed during manual processes has a consistent format.
1 parent 44cc5a1 commit 5485705

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

internal/feedback/feedback.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
package feedback
2626

2727
import (
28+
"fmt"
2829
"log"
30+
"os"
2931
)
3032

3133
// LogError logs non-nil errors and returns whether the error was nil.
@@ -36,3 +38,25 @@ func LogError(err error) bool {
3638
}
3739
return false
3840
}
41+
42+
// Warningf behaves like fmt.Printf but adds a prefix and newline.
43+
func Warningf(format string, v ...interface{}) {
44+
Warning(fmt.Sprintf(format, v...))
45+
}
46+
47+
// Warning behaves like fmt.Println but adds a prefix.
48+
func Warning(v ...interface{}) {
49+
fmt.Fprint(os.Stderr, "warning: ")
50+
fmt.Fprintln(os.Stderr, v...)
51+
}
52+
53+
// Errorf behaves like fmt.Printf but adds a prefix and newline.
54+
func Errorf(format string, v ...interface{}) {
55+
Error(fmt.Sprintf(format, v...))
56+
}
57+
58+
// Error behaves like fmt.Println but adds a prefix.
59+
func Error(v ...interface{}) {
60+
fmt.Fprint(os.Stderr, "error: ")
61+
fmt.Fprintln(os.Stderr, v...)
62+
}

0 commit comments

Comments
 (0)