diff --git a/Makefile b/Makefile index 45bd4bd..ce4cb33 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ all: $(tool).1 cmd/$(tool).go buildlocal cmd/%.go: %.pod echo "package cmd" > cmd/$*.go + echo >> cmd/$*.go echo "var manpage = \`" >> cmd/$*.go pod2text $*.pod >> cmd/$*.go echo "\`" >> cmd/$*.go diff --git a/README.md b/README.md index 7f15f7b..bfb485d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Actions](https://github.com/tlinden/tablizer/actions/workflows/ci.yaml/badge.svg)](https://github.com/tlinden/tablizer/actions) [![License](https://img.shields.io/badge/license-GPL-blue.svg)](https://github.com/tlinden/tablizer/blob/master/LICENSE) +[![Go Report Card](https://goreportcard.com/badge/github.com/tlinden/tablizer)](https://goreportcard.com/report/github.com/tlinden/tablizer) ## tablizer - Manipulate tabular output of other programs diff --git a/cmd/tablizer.go b/cmd/tablizer.go index 54328eb..20a7aa2 100644 --- a/cmd/tablizer.go +++ b/cmd/tablizer.go @@ -1,4 +1,5 @@ package cmd + var manpage = ` NAME tablizer - Manipulate tabular output of other programs @@ -37,7 +38,7 @@ DESCRIPTION You can use tablizer to do these and more things. - tablizer analyses the header fiels of a table, registers the column + tablizer analyses the header fields of a table, registers the column positions of each header field and separates columns by those positions. Without any options it reads its input from "STDIN", but you can also @@ -79,7 +80,7 @@ DESCRIPTION (as in GNU sort(1)). The default sort column is the first one. To disable sorting at all, supply 0 (Zero) to -k. - Finally the -d option enables debugging output which is mostly usefull + Finally the -d option enables debugging output which is mostly useful for the developer. PATTERNS @@ -102,14 +103,14 @@ DESCRIPTION "i" ignore case "m" multiline mode "s" single line mode - Example for a case insensitve search: + Example for a case insensitive search: kubectl get pods -A | tablizer "(?i)account" OUTPUT MODES There might be cases when the tabular output of a program is way too large for your current terminal but you still need to see every column. - In such cases the -o extended or -X option can be usefull which enables + In such cases the -o extended or -X option can be useful which enables *extended mode*. In this mode, each row will be printed vertically, header left, value right, aligned by the field widths. Here's an example: diff --git a/lib/common.go b/lib/common.go index 1279e7c..636fea1 100644 --- a/lib/common.go +++ b/lib/common.go @@ -52,13 +52,13 @@ var ( // colors to be used per supported color mode Colors = map[color.Level]map[string]string{ - color.Level16: map[string]string{ + color.Level16: { "bg": "green", "fg": "black", }, - color.Level256: map[string]string{ + color.Level256: { "bg": "lightGreen", "fg": "black", }, - color.LevelRgb: map[string]string{ + color.LevelRgb: { // FIXME: maybe use something nicer "bg": "lightGreen", "fg": "black", }, @@ -68,7 +68,7 @@ var ( validOutputmodes = "(orgtbl|markdown|extended|ascii)" // main program version - Version = "v1.0.8" + Version = "v1.0.9" // generated version string, used by -v contains lib.Version on // main branch, and lib.Version-$branch-$lastcommit-$date on diff --git a/lib/helpers.go b/lib/helpers.go index 3c4c492..f256a8e 100644 --- a/lib/helpers.go +++ b/lib/helpers.go @@ -87,7 +87,7 @@ func reduceColumns(data *Tabdata) { // exclude columns, if any if len(Columns) > 0 { reducedEntries := [][]string{} - reducedEntry := []string{} + var reducedEntry []string for _, entry := range data.entries { reducedEntry = nil for i, value := range entry { diff --git a/lib/helpers_test.go b/lib/helpers_test.go index cf0ae53..5082697 100644 --- a/lib/helpers_test.go +++ b/lib/helpers_test.go @@ -79,15 +79,15 @@ func TestReduceColumns(t *testing.T) { columns []int }{ { - expect: [][]string{[]string{"a", "b"}}, + expect: [][]string{{"a", "b"}}, columns: []int{1, 2}, }, { - expect: [][]string{[]string{"a", "c"}}, + expect: [][]string{{"a", "c"}}, columns: []int{1, 3}, }, { - expect: [][]string{[]string{"a"}}, + expect: [][]string{{"a"}}, columns: []int{1}, }, { @@ -96,7 +96,7 @@ func TestReduceColumns(t *testing.T) { }, } - input := [][]string{[]string{"a", "b", "c"}} + input := [][]string{{"a", "b", "c"}} Columns = "y" // used as a flag with len(Columns)... diff --git a/lib/parser_test.go b/lib/parser_test.go index 97312d1..fcbd338 100644 --- a/lib/parser_test.go +++ b/lib/parser_test.go @@ -35,10 +35,10 @@ func TestParser(t *testing.T) { "ONE", "TWO", "THREE", }, entries: [][]string{ - []string{ + { "asd", "igig", "cxxxncnc", }, - []string{ + { "19191", "EDD 1", "X", }, }, @@ -69,7 +69,7 @@ func TestParserPatternmatching(t *testing.T) { }{ { entries: [][]string{ - []string{ + { "asd", "igig", "cxxxncnc", }, }, @@ -78,7 +78,7 @@ func TestParserPatternmatching(t *testing.T) { }, { entries: [][]string{ - []string{ + { "19191", "EDD 1", "X", }, }, diff --git a/lib/printer_test.go b/lib/printer_test.go index a615e50..342e2e9 100644 --- a/lib/printer_test.go +++ b/lib/printer_test.go @@ -52,10 +52,10 @@ func TestPrinter(t *testing.T) { "ONE", "TWO", "THREE", }, entries: [][]string{ - []string{ + { "asd", "igig", "cxxxncnc", }, - []string{ + { "19191", "EDD 1", "X", }, }, @@ -100,7 +100,9 @@ THREE(3): X`, t.Run(testname, func(t *testing.T) { OutputMode = mode - data := startdata // we need to reset our mock data, since it's being modified in printData() + // we need to reset our mock data, since it's being + // modified in printData() + data := startdata printData(&data) buf := make([]byte, 1024) @@ -136,13 +138,13 @@ func TestSortPrinter(t *testing.T) { "ONE", "TWO", "THREE", }, entries: [][]string{ - []string{ + { "abc", "345", "b1", }, - []string{ + { "bcd", "234", "a2", }, - []string{ + { "cde", "123", "c3", }, }, diff --git a/tablizer.1 b/tablizer.1 index 766dabd..ae91a00 100644 --- a/tablizer.1 +++ b/tablizer.1 @@ -133,7 +133,7 @@ .\" ======================================================================== .\" .IX Title "TABLIZER 1" -.TH TABLIZER 1 "2022-10-13" "1" "User Commands" +.TH TABLIZER 1 "2022-10-14" "1" "User Commands" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l @@ -177,8 +177,8 @@ not easy to process. .PP You can use \fBtablizer\fR to do these and more things. .PP -\&\fBtablizer\fR analyses the header fiels of a table, registers the column -positions of each header field and separates columns by those +\&\fBtablizer\fR analyses the header fields of a table, registers the +column positions of each header field and separates columns by those positions. .PP Without any options it reads its input from \f(CW\*(C`STDIN\*(C'\fR, but you can also @@ -228,7 +228,7 @@ data (as in \s-1GNU\s0 \fBsort\fR\|(1)). The default sort column is the first on disable sorting at all, supply 0 (Zero) to \-k. .PP Finally the \fB\-d\fR option enables debugging output which is mostly -usefull for the developer. +useful for the developer. .SS "\s-1PATTERNS\s0" .IX Subsection "PATTERNS" You can reduce the rows being displayed by using a regular expression @@ -256,7 +256,7 @@ The most important modifiers are: \&\f(CW\*(C`m\*(C'\fR multiline mode \&\f(CW\*(C`s\*(C'\fR single line mode .PP -Example for a case insensitve search: +Example for a case insensitive search: .PP .Vb 1 \& kubectl get pods \-A | tablizer "(?i)account" @@ -266,7 +266,7 @@ Example for a case insensitve search: There might be cases when the tabular output of a program is way too large for your current terminal but you still need to see every column. In such cases the \fB\-o extended\fR or \fB\-X\fR option can be -usefull which enables \fIextended mode\fR. In this mode, each row will be +useful which enables \fIextended mode\fR. In this mode, each row will be printed vertically, header left, value right, aligned by the field widths. Here's an example: .PP diff --git a/tablizer.pod b/tablizer.pod index 59a88e8..00a8a52 100644 --- a/tablizer.pod +++ b/tablizer.pod @@ -39,8 +39,8 @@ not easy to process. You can use B to do these and more things. -B analyses the header fiels of a table, registers the column -positions of each header field and separates columns by those +B analyses the header fields of a table, registers the +column positions of each header field and separates columns by those positions. Without any options it reads its input from C, but you can also @@ -84,7 +84,7 @@ data (as in GNU sort(1)). The default sort column is the first one. To disable sorting at all, supply 0 (Zero) to -k. Finally the B<-d> option enables debugging output which is mostly -usefull for the developer. +useful for the developer. =head2 PATTERNS @@ -109,7 +109,7 @@ C ignore case C multiline mode C single line mode -Example for a case insensitve search: +Example for a case insensitive search: kubectl get pods -A | tablizer "(?i)account" @@ -119,7 +119,7 @@ Example for a case insensitve search: There might be cases when the tabular output of a program is way too large for your current terminal but you still need to see every column. In such cases the B<-o extended> or B<-X> option can be -usefull which enables I. In this mode, each row will be +useful which enables I. In this mode, each row will be printed vertically, header left, value right, aligned by the field widths. Here's an example: