Skip to content

Commit a9fad6a

Browse files
author
Mercurio
committed
Minor code improvements
1 parent 3c3245b commit a9fad6a

14 files changed

+38
-197
lines changed

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88

99
Limner colorizes and transforms CLI outputs.
1010

11-
<a href="https://github.com/SignorMercurio/limner/blob/main/LICENSE"> <img src="https://img.shields.io/github/license/SignorMercurio/limner?style=for-the-badge" /> </a>
11+
<a href="https://github.com/SignorMercurio/limner/actions"><img src="https://img.shields.io/github/workflow/status/SignorMercurio/limner/Go?logo=GitHub" /></a>
12+
<a href="https://codecov.io/gh/SignorMercurio/limner"><img src="https://codecov.io/gh/SignorMercurio/limner/branch/main/graph/badge.svg?token=PKWZK3BR9R"/></a>
13+
<a href="https://goreportcard.com/report/github.com/SignorMercurio/limner"><img src="https://goreportcard.com/badge/github.com/SignorMercurio/limner" /></a>
14+
<a href="https://github.com/SignorMercurio/limner/blob/main/LICENSE"> <img src="https://img.shields.io/github/license/SignorMercurio/limner" /></a>
1215

1316
</div>
1417

cmd/root.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/SignorMercurio/limner/printer"
99
"github.com/mattn/go-colorable"
10-
"github.com/sirupsen/logrus"
1110
"github.com/spf13/cobra"
1211
"github.com/spf13/viper"
1312
)
@@ -18,9 +17,8 @@ var (
1817
mustType string
1918
input []byte
2019
output []byte
21-
Stdout = colorable.NewColorableStdout()
20+
stdout = colorable.NewColorableStdout()
2221
RootCmd = NewRootCmd()
23-
Log = logrus.New()
2422
)
2523

2624
// getPrinter returns a ColorPrinter
@@ -55,7 +53,7 @@ func NewRootCmd() *cobra.Command {
5553
} else {
5654
p = getPrinter(mustType)
5755
}
58-
p.Print(string(output), Stdout)
56+
p.Print(string(output), stdout)
5957
},
6058
}
6159
cmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.limner.yaml)")
@@ -71,7 +69,7 @@ func Execute() {
7169
defer func() { recover() }()
7270
err := RootCmd.Execute()
7371
if err != nil {
74-
Log.Panic(err)
72+
fmt.Println(err)
7573
}
7674
}
7775

coverage.out

-147
This file was deleted.

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.17
55
require (
66
github.com/google/go-cmp v0.5.6
77
github.com/mattn/go-colorable v0.1.11
8-
github.com/sirupsen/logrus v1.8.1
98
github.com/spf13/cobra v1.2.1
109
github.com/spf13/viper v1.9.0
1110
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb
255255
github.com/sagikazarmark/crypt v0.1.0/go.mod h1:B/mN0msZuINBtQ1zZLEQcegFJJf9vnYIR88KRMEuODE=
256256
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
257257
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
258-
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
259-
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
260258
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
261259
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
262260
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=

in.txt

-4
This file was deleted.

out.txt

-5
This file was deleted.

printer/color.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type ColorPrinter struct {
1414
}
1515

1616
func (cp *ColorPrinter) Print(buf string, w io.Writer) {
17-
var printer Printer = &SingleColorPrinter{Color: StringColor}
17+
var printer Printer = &SingleColorPrinter{Color: stringColor}
1818
var jsonObj map[string]interface{}
1919

2020
// change the printer if type is already enforced

printer/color_theme.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
)
77

88
var (
9-
KeyColor = color.Red
10-
StringColor = color.Green
11-
BoolColor = color.Yellow
12-
NumberColor = color.Yellow
13-
NullColor = color.Cyan
14-
HeaderColor = color.Blue
9+
keyColor = color.Red
10+
stringColor = color.Green
11+
boolColor = color.Yellow
12+
numberColor = color.Yellow
13+
nullColor = color.Cyan
14+
headerColor = color.Blue
1515

16-
ColumnColors = []color.Color{
16+
columnColors = []color.Color{
1717
color.White,
1818
color.Cyan,
1919
}
@@ -58,20 +58,20 @@ func InitColorTheme() {
5858
colorVal := str2color(val)
5959
switch key {
6060
case "key_color":
61-
KeyColor = colorVal
61+
keyColor = colorVal
6262
case "string_color":
63-
StringColor = colorVal
63+
stringColor = colorVal
6464
case "bool_color":
65-
BoolColor = colorVal
65+
boolColor = colorVal
6666
case "number_color":
67-
NumberColor = colorVal
67+
numberColor = colorVal
6868
case "null_color":
69-
NullColor = colorVal
69+
nullColor = colorVal
7070
case "header_color":
71-
HeaderColor = colorVal
71+
headerColor = colorVal
7272
}
7373
case []interface{}:
74-
ColumnColors = slice2color(val)
74+
columnColors = slice2color(val)
7575
}
7676
}
7777
}

printer/format.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func isNum(value string) bool {
4343
func getColorByValueType(value string) color.Color {
4444
switch {
4545
case isNull(value):
46-
return NullColor
46+
return nullColor
4747
case isBool(value):
48-
return BoolColor
48+
return boolColor
4949
case isNum(value):
50-
return NumberColor
50+
return numberColor
5151
default:
52-
return StringColor
52+
return stringColor
5353
}
5454
}

printer/json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (jp *JsonPrinter) colorKey(key string) string {
5858
key = strings.TrimSuffix(key, ":")
5959
key = strings.Trim(key, `"`)
6060

61-
return fmt.Sprint(color.Apply(key, KeyColor))
61+
return fmt.Sprint(color.Apply(key, keyColor))
6262
}
6363

6464
// colorValue colorizes json values

printer/seems.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,11 @@ func seemsReadyStatus(status string) (color.Color, bool) {
7272
ready := strings.Split(status, "/")
7373
if ready[0] == ready[1] {
7474
return color.Green, true
75-
} else {
76-
_, e1 := strconv.Atoi(ready[0])
77-
_, e2 := strconv.Atoi(ready[1])
78-
if e1 == nil && e2 == nil {
79-
return color.Yellow, true
80-
}
75+
}
76+
_, e1 := strconv.Atoi(ready[0])
77+
_, e2 := strconv.Atoi(ready[1])
78+
if e1 == nil && e2 == nil {
79+
return color.Yellow, true
8180
}
8281
}
8382
return 0, false

printer/table.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ type TablePrinter struct {
1616
func (tp *TablePrinter) Print(buf string, w io.Writer) {
1717
for _, line := range strings.Split(buf, "\n") {
1818
if tp.isHeader(line) {
19-
fmt.Fprintln(w, color.Apply(line, HeaderColor))
19+
fmt.Fprintln(w, color.Apply(line, headerColor))
2020
tp.firstLine = false
2121
continue
2222
}
2323

24-
tp.printTable(w, line, ColumnColors)
24+
tp.printTable(w, line, columnColors)
2525
}
2626
}
2727

printer/yaml.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ func (yp *YamlPrinter) printYaml(line string, w io.Writer) {
6464
columns := spaces.Split(line, -1)
6565
if len(columns) >= 2 {
6666
if !yp.inTable {
67-
fmt.Fprintln(w, color.Apply(key, HeaderColor))
67+
fmt.Fprintln(w, color.Apply(key, headerColor))
6868
yp.inTable = true
6969
} else {
70-
NewTablePrinter(ColorStatus).printTable(w, key, ColumnColors)
70+
NewTablePrinter(ColorStatus).printTable(w, key, columnColors)
7171
}
7272
return
7373
}
@@ -104,7 +104,7 @@ func (yp *YamlPrinter) colorString(line string) string {
104104

105105
line = strings.Trim(line, `"`)
106106

107-
return fmt.Sprintf(format, color.Apply(line, StringColor))
107+
return fmt.Sprintf(format, color.Apply(line, stringColor))
108108
}
109109

110110
// colorKey colorizes yaml keys
@@ -120,7 +120,7 @@ func (yp *YamlPrinter) colorKey(key string) string {
120120
key = strings.TrimSuffix(key, ":")
121121
key = strings.TrimPrefix(key, "- ")
122122

123-
return fmt.Sprintf(format, color.Apply(key, KeyColor))
123+
return fmt.Sprintf(format, color.Apply(key, keyColor))
124124
}
125125

126126
// colorValue colorizes yaml values

0 commit comments

Comments
 (0)