mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
using enum modeflags, use my own usage template, generated from manpage so I don't have to maintain it twice, it's also nicer
This commit is contained in:
4
Makefile
4
Makefile
@@ -41,6 +41,10 @@ cmd/%.go: %.pod
|
|||||||
pod2text $*.pod >> cmd/$*.go
|
pod2text $*.pod >> cmd/$*.go
|
||||||
echo "\`" >> cmd/$*.go
|
echo "\`" >> cmd/$*.go
|
||||||
|
|
||||||
|
echo "var usage = \`" >> cmd/$*.go
|
||||||
|
awk '/SYNOPS/{f=1;next} /DESCR/{f=0} f' $*.pod | sed 's/^ //' >> cmd/$*.go
|
||||||
|
echo "\`" >> cmd/$*.go
|
||||||
|
|
||||||
buildlocal:
|
buildlocal:
|
||||||
go build -ldflags "-X 'github.com/tlinden/tablizer/cfg.VERSION=$(VERSION)'"
|
go build -ldflags "-X 'github.com/tlinden/tablizer/cfg.VERSION=$(VERSION)'"
|
||||||
|
|
||||||
|
|||||||
@@ -17,15 +17,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
"regexp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultSeparator string = `(\s\s+|\t)`
|
const DefaultSeparator string = `(\s\s+|\t)`
|
||||||
const ValidOutputModes string = "(orgtbl|markdown|extended|ascii|yaml|shell)"
|
const Version string = "v1.0.12"
|
||||||
const Version string = "v1.0.11"
|
|
||||||
|
|
||||||
var VERSION string // maintained by -x
|
var VERSION string // maintained by -x
|
||||||
|
|
||||||
@@ -35,7 +32,7 @@ type Config struct {
|
|||||||
Columns string
|
Columns string
|
||||||
UseColumns []int
|
UseColumns []int
|
||||||
Separator string
|
Separator string
|
||||||
OutputMode string
|
OutputMode int
|
||||||
InvertMatch bool
|
InvertMatch bool
|
||||||
Pattern string
|
Pattern string
|
||||||
|
|
||||||
@@ -64,6 +61,16 @@ type Modeflag struct {
|
|||||||
A bool
|
A bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// used for switching printers
|
||||||
|
const (
|
||||||
|
Extended = iota + 1
|
||||||
|
Orgtbl
|
||||||
|
Markdown
|
||||||
|
Shell
|
||||||
|
Yaml
|
||||||
|
Ascii
|
||||||
|
)
|
||||||
|
|
||||||
// various sort types
|
// various sort types
|
||||||
type Sortmode struct {
|
type Sortmode struct {
|
||||||
Numeric bool
|
Numeric bool
|
||||||
@@ -97,39 +104,6 @@ func Getversion() string {
|
|||||||
return fmt.Sprintf("This is tablizer version %s", VERSION)
|
return fmt.Sprintf("This is tablizer version %s", VERSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conf *Config) PrepareModeFlags(flag Modeflag, mode string) error {
|
|
||||||
if len(mode) == 0 {
|
|
||||||
// associate short flags like -X with mode selector
|
|
||||||
switch {
|
|
||||||
case flag.X:
|
|
||||||
conf.OutputMode = "extended"
|
|
||||||
case flag.M:
|
|
||||||
conf.OutputMode = "markdown"
|
|
||||||
case flag.O:
|
|
||||||
conf.OutputMode = "orgtbl"
|
|
||||||
case flag.S:
|
|
||||||
conf.OutputMode = "shell"
|
|
||||||
conf.NoNumbering = true
|
|
||||||
case flag.Y:
|
|
||||||
conf.OutputMode = "yaml"
|
|
||||||
conf.NoNumbering = true
|
|
||||||
default:
|
|
||||||
conf.OutputMode = "ascii"
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
r, _ := regexp.Compile(ValidOutputModes) // hardcoded, no fail expected
|
|
||||||
match := r.MatchString(mode)
|
|
||||||
|
|
||||||
if !match {
|
|
||||||
return errors.New("Invalid output mode!")
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.OutputMode = mode
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conf *Config) PrepareSortFlags(flag Sortmode) {
|
func (conf *Config) PrepareSortFlags(flag Sortmode) {
|
||||||
switch {
|
switch {
|
||||||
case flag.Numeric:
|
case flag.Numeric:
|
||||||
@@ -142,3 +116,20 @@ func (conf *Config) PrepareSortFlags(flag Sortmode) {
|
|||||||
conf.SortMode = "string"
|
conf.SortMode = "string"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (conf *Config) PrepareModeFlags(flag Modeflag) {
|
||||||
|
switch {
|
||||||
|
case flag.X:
|
||||||
|
conf.OutputMode = Extended
|
||||||
|
case flag.O:
|
||||||
|
conf.OutputMode = Orgtbl
|
||||||
|
case flag.M:
|
||||||
|
conf.OutputMode = Markdown
|
||||||
|
case flag.S:
|
||||||
|
conf.OutputMode = Shell
|
||||||
|
case flag.Y:
|
||||||
|
conf.OutputMode = Yaml
|
||||||
|
default:
|
||||||
|
conf.OutputMode = Ascii
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,46 +26,26 @@ import (
|
|||||||
func TestPrepareModeFlags(t *testing.T) {
|
func TestPrepareModeFlags(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
flag Modeflag
|
flag Modeflag
|
||||||
mode string // input, if any
|
expect int // output (constant enum)
|
||||||
expect string // output
|
|
||||||
want bool
|
|
||||||
}{
|
}{
|
||||||
// short commandline flags like -M
|
// short commandline flags like -M
|
||||||
{Modeflag{X: true}, "", "extended", false},
|
{Modeflag{X: true}, Extended},
|
||||||
{Modeflag{S: true}, "", "shell", false},
|
{Modeflag{S: true}, Shell},
|
||||||
{Modeflag{O: true}, "", "orgtbl", false},
|
{Modeflag{O: true}, Orgtbl},
|
||||||
{Modeflag{Y: true}, "", "yaml", false},
|
{Modeflag{Y: true}, Yaml},
|
||||||
{Modeflag{M: true}, "", "markdown", false},
|
{Modeflag{M: true}, Markdown},
|
||||||
{Modeflag{}, "", "ascii", false},
|
{Modeflag{}, Ascii},
|
||||||
|
|
||||||
// long flags like -o yaml
|
|
||||||
{Modeflag{}, "extended", "extended", false},
|
|
||||||
{Modeflag{}, "shell", "shell", false},
|
|
||||||
{Modeflag{}, "orgtbl", "orgtbl", false},
|
|
||||||
{Modeflag{}, "yaml", "yaml", false},
|
|
||||||
{Modeflag{}, "markdown", "markdown", false},
|
|
||||||
|
|
||||||
// failing
|
|
||||||
{Modeflag{}, "blah", "", true},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: use a map for easier printing
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
testname := fmt.Sprintf("PrepareModeFlags-flags-mode-%s-expect-%s-want-%t",
|
testname := fmt.Sprintf("PrepareModeFlags-expect-%d", tt.expect)
|
||||||
tt.mode, tt.expect, tt.want)
|
|
||||||
t.Run(testname, func(t *testing.T) {
|
t.Run(testname, func(t *testing.T) {
|
||||||
c := Config{OutputMode: tt.mode}
|
c := Config{}
|
||||||
|
|
||||||
// check either flag or pre filled mode, whatever is defined in tt
|
c.PrepareModeFlags(tt.flag)
|
||||||
err := c.PrepareModeFlags(tt.flag, tt.mode)
|
if c.OutputMode != tt.expect {
|
||||||
if err != nil {
|
t.Errorf("got: %d, expect: %d", c.OutputMode, tt.expect)
|
||||||
if !tt.want {
|
|
||||||
// expect to fail
|
|
||||||
t.Fatalf("PrepareModeFlags returned unexpected error: %s", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if c.OutputMode != tt.expect {
|
|
||||||
t.Errorf("got: %s, expect: %s", c.OutputMode, tt.expect)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
21
cmd/root.go
21
cmd/root.go
@@ -25,6 +25,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func man() {
|
func man() {
|
||||||
@@ -48,7 +49,6 @@ func Execute() {
|
|||||||
var (
|
var (
|
||||||
conf cfg.Config
|
conf cfg.Config
|
||||||
ShowManual bool
|
ShowManual bool
|
||||||
Outputmode string
|
|
||||||
ShowVersion bool
|
ShowVersion bool
|
||||||
modeflag cfg.Modeflag
|
modeflag cfg.Modeflag
|
||||||
sortmode cfg.Sortmode
|
sortmode cfg.Sortmode
|
||||||
@@ -70,11 +70,7 @@ func Execute() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prepare flags
|
// prepare flags
|
||||||
err := conf.PrepareModeFlags(modeflag, Outputmode)
|
conf.PrepareModeFlags(modeflag)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
conf.PrepareSortFlags(sortmode)
|
conf.PrepareSortFlags(sortmode)
|
||||||
|
|
||||||
// actual execution starts here
|
// actual execution starts here
|
||||||
@@ -94,26 +90,23 @@ func Execute() {
|
|||||||
|
|
||||||
// sort options
|
// sort options
|
||||||
rootCmd.PersistentFlags().IntVarP(&conf.SortByColumn, "sort-by", "k", 0, "Sort by column (default: 1)")
|
rootCmd.PersistentFlags().IntVarP(&conf.SortByColumn, "sort-by", "k", 0, "Sort by column (default: 1)")
|
||||||
|
|
||||||
|
// sort mode, only 1 allowed
|
||||||
rootCmd.PersistentFlags().BoolVarP(&conf.SortDescending, "sort-desc", "D", false, "Sort in descending order (default: ascending)")
|
rootCmd.PersistentFlags().BoolVarP(&conf.SortDescending, "sort-desc", "D", false, "Sort in descending order (default: ascending)")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&sortmode.Numeric, "sort-numeric", "i", false, "sort according to string numerical value")
|
rootCmd.PersistentFlags().BoolVarP(&sortmode.Numeric, "sort-numeric", "i", false, "sort according to string numerical value")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&sortmode.Time, "sort-time", "t", false, "sort according to time string")
|
rootCmd.PersistentFlags().BoolVarP(&sortmode.Time, "sort-time", "t", false, "sort according to time string")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&sortmode.Age, "sort-age", "a", false, "sort according to age (duration) string")
|
rootCmd.PersistentFlags().BoolVarP(&sortmode.Age, "sort-age", "a", false, "sort according to age (duration) string")
|
||||||
|
rootCmd.MarkFlagsMutuallyExclusive("sort-desc", "sort-numeric", "sort-time", "sort-age")
|
||||||
|
|
||||||
// output flags, only 1 allowed, hidden, since just short cuts
|
// output flags, only 1 allowed
|
||||||
rootCmd.PersistentFlags().BoolVarP(&modeflag.X, "extended", "X", false, "Enable extended output")
|
rootCmd.PersistentFlags().BoolVarP(&modeflag.X, "extended", "X", false, "Enable extended output")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&modeflag.M, "markdown", "M", false, "Enable markdown table output")
|
rootCmd.PersistentFlags().BoolVarP(&modeflag.M, "markdown", "M", false, "Enable markdown table output")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&modeflag.O, "orgtbl", "O", false, "Enable org-mode table output")
|
rootCmd.PersistentFlags().BoolVarP(&modeflag.O, "orgtbl", "O", false, "Enable org-mode table output")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&modeflag.S, "shell", "S", false, "Enable shell mode output")
|
rootCmd.PersistentFlags().BoolVarP(&modeflag.S, "shell", "S", false, "Enable shell mode output")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&modeflag.Y, "yaml", "Y", false, "Enable yaml output")
|
rootCmd.PersistentFlags().BoolVarP(&modeflag.Y, "yaml", "Y", false, "Enable yaml output")
|
||||||
rootCmd.MarkFlagsMutuallyExclusive("extended", "markdown", "orgtbl", "shell", "yaml")
|
rootCmd.MarkFlagsMutuallyExclusive("extended", "markdown", "orgtbl", "shell", "yaml")
|
||||||
_ = rootCmd.Flags().MarkHidden("extended")
|
|
||||||
_ = rootCmd.Flags().MarkHidden("orgtbl")
|
|
||||||
_ = rootCmd.Flags().MarkHidden("markdown")
|
|
||||||
_ = rootCmd.Flags().MarkHidden("shell")
|
|
||||||
_ = rootCmd.Flags().MarkHidden("yaml")
|
|
||||||
|
|
||||||
// same thing but more common, takes precedence over above group
|
rootCmd.SetUsageTemplate(strings.TrimSpace(usage) + "\n")
|
||||||
rootCmd.PersistentFlags().StringVarP(&Outputmode, "output", "o", "", "Output mode - one of: orgtbl, markdown, extended, shell, ascii(default)")
|
|
||||||
|
|
||||||
err := rootCmd.Execute()
|
err := rootCmd.Execute()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -8,24 +8,32 @@ SYNOPSIS
|
|||||||
Usage:
|
Usage:
|
||||||
tablizer [regex] [file, ...] [flags]
|
tablizer [regex] [file, ...] [flags]
|
||||||
|
|
||||||
Flags:
|
Operational Flags:
|
||||||
-c, --columns string Only show the speficied columns (separated by ,)
|
-c, --columns string Only show the speficied columns (separated by ,)
|
||||||
-d, --debug Enable debugging
|
|
||||||
-h, --help help for tablizer
|
|
||||||
-v, --invert-match select non-matching rows
|
-v, --invert-match select non-matching rows
|
||||||
-m, --man Display manual page
|
|
||||||
-n, --no-numbering Disable header numbering
|
-n, --no-numbering Disable header numbering
|
||||||
-N, --no-color Disable pattern highlighting
|
-N, --no-color Disable pattern highlighting
|
||||||
-o, --output string Output mode - one of: orgtbl, markdown, extended, yaml, ascii(default)
|
-s, --separator string Custom field separator
|
||||||
|
-k, --sort-by int Sort by column (default: 1)
|
||||||
|
|
||||||
|
Output Flags (mutually exclusive):
|
||||||
-X, --extended Enable extended output
|
-X, --extended Enable extended output
|
||||||
-M, --markdown Enable markdown table output
|
-M, --markdown Enable markdown table output
|
||||||
-O, --orgtbl Enable org-mode table output
|
-O, --orgtbl Enable org-mode table output
|
||||||
-s, --separator string Custom field separator
|
-S, --shell Enable shell evaluable ouput
|
||||||
|
-Y, --yaml Enable yaml output
|
||||||
|
-A, --ascii Default output mode, ascii tabular
|
||||||
|
|
||||||
|
Sort Mode Flags (mutually exclusive):
|
||||||
-a, --sort-age sort according to age (duration) string
|
-a, --sort-age sort according to age (duration) string
|
||||||
-k, --sort-by int Sort by column (default: 1)
|
|
||||||
-D, --sort-desc Sort in descending order (default: ascending)
|
-D, --sort-desc Sort in descending order (default: ascending)
|
||||||
-i, --sort-numeric sort according to string numerical value
|
-i, --sort-numeric sort according to string numerical value
|
||||||
-t, --sort-time sort according to time string
|
-t, --sort-time sort according to time string
|
||||||
|
|
||||||
|
Other Flags:
|
||||||
|
-d, --debug Enable debugging
|
||||||
|
-h, --help help for tablizer
|
||||||
|
-m, --man Display manual page
|
||||||
-v, --version Print program version
|
-v, --version Print program version
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
@@ -205,3 +213,38 @@ AUTHORS
|
|||||||
Thomas von Dein tom AT vondein DOT org
|
Thomas von Dein tom AT vondein DOT org
|
||||||
|
|
||||||
`
|
`
|
||||||
|
var usage = `
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
tablizer [regex] [file, ...] [flags]
|
||||||
|
|
||||||
|
Operational Flags:
|
||||||
|
-c, --columns string Only show the speficied columns (separated by ,)
|
||||||
|
-v, --invert-match select non-matching rows
|
||||||
|
-n, --no-numbering Disable header numbering
|
||||||
|
-N, --no-color Disable pattern highlighting
|
||||||
|
-s, --separator string Custom field separator
|
||||||
|
-k, --sort-by int Sort by column (default: 1)
|
||||||
|
|
||||||
|
Output Flags (mutually exclusive):
|
||||||
|
-X, --extended Enable extended output
|
||||||
|
-M, --markdown Enable markdown table output
|
||||||
|
-O, --orgtbl Enable org-mode table output
|
||||||
|
-S, --shell Enable shell evaluable ouput
|
||||||
|
-Y, --yaml Enable yaml output
|
||||||
|
-A, --ascii Default output mode, ascii tabular
|
||||||
|
|
||||||
|
Sort Mode Flags (mutually exclusive):
|
||||||
|
-a, --sort-age sort according to age (duration) string
|
||||||
|
-D, --sort-desc Sort in descending order (default: ascending)
|
||||||
|
-i, --sort-numeric sort according to string numerical value
|
||||||
|
-t, --sort-time sort according to time string
|
||||||
|
|
||||||
|
Other Flags:
|
||||||
|
-d, --debug Enable debugging
|
||||||
|
-h, --help help for tablizer
|
||||||
|
-m, --man Display manual page
|
||||||
|
-v, --version Print program version
|
||||||
|
|
||||||
|
|
||||||
|
`
|
||||||
|
|||||||
@@ -43,21 +43,22 @@ func printData(w io.Writer, c cfg.Config, data *Tabdata) {
|
|||||||
sortTable(c, data)
|
sortTable(c, data)
|
||||||
|
|
||||||
switch c.OutputMode {
|
switch c.OutputMode {
|
||||||
case "extended":
|
case cfg.Extended:
|
||||||
printExtendedData(w, c, data)
|
printExtendedData(w, c, data)
|
||||||
case "ascii":
|
case cfg.Ascii:
|
||||||
printAsciiData(w, c, data)
|
printAsciiData(w, c, data)
|
||||||
case "orgtbl":
|
case cfg.Orgtbl:
|
||||||
printOrgmodeData(w, c, data)
|
printOrgmodeData(w, c, data)
|
||||||
case "markdown":
|
case cfg.Markdown:
|
||||||
printMarkdownData(w, c, data)
|
printMarkdownData(w, c, data)
|
||||||
case "shell":
|
case cfg.Shell:
|
||||||
printShellData(w, c, data)
|
printShellData(w, c, data)
|
||||||
case "yaml":
|
case cfg.Yaml:
|
||||||
printYamlData(w, c, data)
|
printYamlData(w, c, data)
|
||||||
default:
|
default:
|
||||||
printAsciiData(w, c, data)
|
printAsciiData(w, c, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func output(w io.Writer, str string) {
|
func output(w io.Writer, str string) {
|
||||||
|
|||||||
@@ -72,14 +72,14 @@ var tests = []struct {
|
|||||||
column int // sort by this column, 0 == default first or NO Sort
|
column int // sort by this column, 0 == default first or NO Sort
|
||||||
desc bool // sort in descending order, default == ascending
|
desc bool // sort in descending order, default == ascending
|
||||||
nonum bool // hide numbering
|
nonum bool // hide numbering
|
||||||
mode string // shell, orgtbl, etc. empty == default: ascii
|
mode int // shell, orgtbl, etc. empty == default: ascii
|
||||||
usecol []int // columns to display, empty == display all
|
usecol []int // columns to display, empty == display all
|
||||||
usecolstr string // for testname, must match usecol
|
usecolstr string // for testname, must match usecol
|
||||||
expect string // rendered output we expect
|
expect string // rendered output we expect
|
||||||
}{
|
}{
|
||||||
// --------------------- Default settings mode tests ``
|
// --------------------- Default settings mode tests ``
|
||||||
{
|
{
|
||||||
mode: "ascii",
|
mode: cfg.Ascii,
|
||||||
name: "default",
|
name: "default",
|
||||||
expect: `
|
expect: `
|
||||||
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
NAME(1) DURATION(2) COUNT(3) WHEN(4)
|
||||||
@@ -89,7 +89,7 @@ ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default",
|
name: "default",
|
||||||
mode: "orgtbl",
|
mode: cfg.Orgtbl,
|
||||||
expect: `
|
expect: `
|
||||||
+---------+-------------+----------+----------------------------+
|
+---------+-------------+----------+----------------------------+
|
||||||
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
||||||
@@ -101,7 +101,7 @@ ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default",
|
name: "default",
|
||||||
mode: "markdown",
|
mode: cfg.Markdown,
|
||||||
expect: `
|
expect: `
|
||||||
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
| NAME(1) | DURATION(2) | COUNT(3) | WHEN(4) |
|
||||||
|---------|-------------|----------|----------------------------|
|
|---------|-------------|----------|----------------------------|
|
||||||
@@ -111,7 +111,7 @@ ceta 33d12h 9 06/Jan/2008 15:04:05 -0700`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default",
|
name: "default",
|
||||||
mode: "shell",
|
mode: cfg.Shell,
|
||||||
nonum: true,
|
nonum: true,
|
||||||
expect: `
|
expect: `
|
||||||
NAME="beta" DURATION="1d10h5m1s" COUNT="33" WHEN="3/1/2014"
|
NAME="beta" DURATION="1d10h5m1s" COUNT="33" WHEN="3/1/2014"
|
||||||
@@ -120,7 +120,7 @@ NAME="ceta" DURATION="33d12h" COUNT="9" WHEN="06/Jan/2008 15:04:05 -0700"`,
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default",
|
name: "default",
|
||||||
mode: "yaml",
|
mode: cfg.Yaml,
|
||||||
nonum: true,
|
nonum: true,
|
||||||
expect: `
|
expect: `
|
||||||
entries:
|
entries:
|
||||||
@@ -139,7 +139,7 @@ entries:
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "default",
|
name: "default",
|
||||||
mode: "extended",
|
mode: cfg.Extended,
|
||||||
expect: `
|
expect: `
|
||||||
NAME(1): beta
|
NAME(1): beta
|
||||||
DURATION(2): 1d10h5m1s
|
DURATION(2): 1d10h5m1s
|
||||||
@@ -248,7 +248,7 @@ DURATION(2) WHEN(4)
|
|||||||
|
|
||||||
func TestPrinter(t *testing.T) {
|
func TestPrinter(t *testing.T) {
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
testname := fmt.Sprintf("print-sortcol-%d-desc-%t-sortby-%s-mode-%s-usecolumns-%s",
|
testname := fmt.Sprintf("print-sortcol-%d-desc-%t-sortby-%s-mode-%d-usecolumns-%s",
|
||||||
tt.column, tt.desc, tt.sortby, tt.mode, tt.usecolstr)
|
tt.column, tt.desc, tt.sortby, tt.mode, tt.usecolstr)
|
||||||
t.Run(testname, func(t *testing.T) {
|
t.Run(testname, func(t *testing.T) {
|
||||||
// replaces os.Stdout, but we ignore it
|
// replaces os.Stdout, but we ignore it
|
||||||
|
|||||||
24
tablizer.1
24
tablizer.1
@@ -133,7 +133,7 @@
|
|||||||
.\" ========================================================================
|
.\" ========================================================================
|
||||||
.\"
|
.\"
|
||||||
.IX Title "TABLIZER 1"
|
.IX Title "TABLIZER 1"
|
||||||
.TH TABLIZER 1 "2022-10-16" "1" "User Commands"
|
.TH TABLIZER 1 "2022-10-21" "1" "User Commands"
|
||||||
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
|
||||||
.\" way too many mistakes in technical documents.
|
.\" way too many mistakes in technical documents.
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
@@ -146,24 +146,32 @@ tablizer \- Manipulate tabular output of other programs
|
|||||||
\& Usage:
|
\& Usage:
|
||||||
\& tablizer [regex] [file, ...] [flags]
|
\& tablizer [regex] [file, ...] [flags]
|
||||||
\&
|
\&
|
||||||
\& Flags:
|
\& Operational Flags:
|
||||||
\& \-c, \-\-columns string Only show the speficied columns (separated by ,)
|
\& \-c, \-\-columns string Only show the speficied columns (separated by ,)
|
||||||
\& \-d, \-\-debug Enable debugging
|
|
||||||
\& \-h, \-\-help help for tablizer
|
|
||||||
\& \-v, \-\-invert\-match select non\-matching rows
|
\& \-v, \-\-invert\-match select non\-matching rows
|
||||||
\& \-m, \-\-man Display manual page
|
|
||||||
\& \-n, \-\-no\-numbering Disable header numbering
|
\& \-n, \-\-no\-numbering Disable header numbering
|
||||||
\& \-N, \-\-no\-color Disable pattern highlighting
|
\& \-N, \-\-no\-color Disable pattern highlighting
|
||||||
\& \-o, \-\-output string Output mode \- one of: orgtbl, markdown, extended, yaml, ascii(default)
|
\& \-s, \-\-separator string Custom field separator
|
||||||
|
\& \-k, \-\-sort\-by int Sort by column (default: 1)
|
||||||
|
\&
|
||||||
|
\& Output Flags (mutually exclusive):
|
||||||
\& \-X, \-\-extended Enable extended output
|
\& \-X, \-\-extended Enable extended output
|
||||||
\& \-M, \-\-markdown Enable markdown table output
|
\& \-M, \-\-markdown Enable markdown table output
|
||||||
\& \-O, \-\-orgtbl Enable org\-mode table output
|
\& \-O, \-\-orgtbl Enable org\-mode table output
|
||||||
\& \-s, \-\-separator string Custom field separator
|
\& \-S, \-\-shell Enable shell evaluable ouput
|
||||||
|
\& \-Y, \-\-yaml Enable yaml output
|
||||||
|
\& \-A, \-\-ascii Default output mode, ascii tabular
|
||||||
|
\&
|
||||||
|
\& Sort Mode Flags (mutually exclusive):
|
||||||
\& \-a, \-\-sort\-age sort according to age (duration) string
|
\& \-a, \-\-sort\-age sort according to age (duration) string
|
||||||
\& \-k, \-\-sort\-by int Sort by column (default: 1)
|
|
||||||
\& \-D, \-\-sort\-desc Sort in descending order (default: ascending)
|
\& \-D, \-\-sort\-desc Sort in descending order (default: ascending)
|
||||||
\& \-i, \-\-sort\-numeric sort according to string numerical value
|
\& \-i, \-\-sort\-numeric sort according to string numerical value
|
||||||
\& \-t, \-\-sort\-time sort according to time string
|
\& \-t, \-\-sort\-time sort according to time string
|
||||||
|
\&
|
||||||
|
\& Other Flags:
|
||||||
|
\& \-d, \-\-debug Enable debugging
|
||||||
|
\& \-h, \-\-help help for tablizer
|
||||||
|
\& \-m, \-\-man Display manual page
|
||||||
\& \-v, \-\-version Print program version
|
\& \-v, \-\-version Print program version
|
||||||
.Ve
|
.Ve
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
|
|||||||
22
tablizer.pod
22
tablizer.pod
@@ -7,24 +7,32 @@ tablizer - Manipulate tabular output of other programs
|
|||||||
Usage:
|
Usage:
|
||||||
tablizer [regex] [file, ...] [flags]
|
tablizer [regex] [file, ...] [flags]
|
||||||
|
|
||||||
Flags:
|
Operational Flags:
|
||||||
-c, --columns string Only show the speficied columns (separated by ,)
|
-c, --columns string Only show the speficied columns (separated by ,)
|
||||||
-d, --debug Enable debugging
|
|
||||||
-h, --help help for tablizer
|
|
||||||
-v, --invert-match select non-matching rows
|
-v, --invert-match select non-matching rows
|
||||||
-m, --man Display manual page
|
|
||||||
-n, --no-numbering Disable header numbering
|
-n, --no-numbering Disable header numbering
|
||||||
-N, --no-color Disable pattern highlighting
|
-N, --no-color Disable pattern highlighting
|
||||||
-o, --output string Output mode - one of: orgtbl, markdown, extended, yaml, ascii(default)
|
-s, --separator string Custom field separator
|
||||||
|
-k, --sort-by int Sort by column (default: 1)
|
||||||
|
|
||||||
|
Output Flags (mutually exclusive):
|
||||||
-X, --extended Enable extended output
|
-X, --extended Enable extended output
|
||||||
-M, --markdown Enable markdown table output
|
-M, --markdown Enable markdown table output
|
||||||
-O, --orgtbl Enable org-mode table output
|
-O, --orgtbl Enable org-mode table output
|
||||||
-s, --separator string Custom field separator
|
-S, --shell Enable shell evaluable ouput
|
||||||
|
-Y, --yaml Enable yaml output
|
||||||
|
-A, --ascii Default output mode, ascii tabular
|
||||||
|
|
||||||
|
Sort Mode Flags (mutually exclusive):
|
||||||
-a, --sort-age sort according to age (duration) string
|
-a, --sort-age sort according to age (duration) string
|
||||||
-k, --sort-by int Sort by column (default: 1)
|
|
||||||
-D, --sort-desc Sort in descending order (default: ascending)
|
-D, --sort-desc Sort in descending order (default: ascending)
|
||||||
-i, --sort-numeric sort according to string numerical value
|
-i, --sort-numeric sort according to string numerical value
|
||||||
-t, --sort-time sort according to time string
|
-t, --sort-time sort according to time string
|
||||||
|
|
||||||
|
Other Flags:
|
||||||
|
-d, --debug Enable debugging
|
||||||
|
-h, --help help for tablizer
|
||||||
|
-m, --man Display manual page
|
||||||
-v, --version Print program version
|
-v, --version Print program version
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user