Passed
Push — master ( 70cd71...7d7337 )
by Valentin
02:17
created

util/log/cprint.go   A

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
dl 0
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A log.init 0 2 1
A log.printf 0 2 1
A log.sprintf 0 6 2
1
package log
2
3
import (
4
	"fmt"
5
	"github.com/mgutz/ansi"
6
	"regexp"
7
	"strings"
8
)
9
10
var reg *regexp.Regexp
11
12
func init() {
13
	reg, _ = regexp.Compile(`<([^>]+)>`)
14
}
15
16
// Printf works identically to fmt.Print but adds `<white+hb>color formatting support for CLI</reset>`.
17
func printf(format string, args ...interface{}) {
18
	fmt.Print(sprintf(format, args...))
0 ignored issues
show
introduced by
can't check non-constant format in call to sprintf
Loading history...
19
}
20
21
// Sprintf works identically to fmt.Sprintf but adds `<white+hb>color formatting support for CLI</reset>`.
22
func sprintf(format string, args ...interface{}) string {
23
	format = reg.ReplaceAllStringFunc(format, func(s string) string {
24
		return ansi.ColorCode(strings.Trim(s, "<>/"))
25
	})
26
27
	return fmt.Sprintf(format, args...)
0 ignored issues
show
introduced by
can't check non-constant format in call to Sprintf
Loading history...
28
}
29