added --no-headers flag to disable header display in tabular modes

This commit is contained in:
2023-04-21 09:52:05 +02:00
parent 195f685584
commit 1acbdbc674
6 changed files with 37 additions and 14 deletions

View File

@@ -25,13 +25,14 @@ import (
) )
const DefaultSeparator string = `(\s\s+|\t)` const DefaultSeparator string = `(\s\s+|\t)`
const Version string = "v1.0.14" const Version string = "v1.0.15"
var VERSION string // maintained by -x var VERSION string // maintained by -x
type Config struct { type Config struct {
Debug bool Debug bool
NoNumbering bool NoNumbering bool
NoHeaders bool
Columns string Columns string
UseColumns []int UseColumns []int
Separator string Separator string

View File

@@ -105,6 +105,7 @@ func Execute() {
// options // options
rootCmd.PersistentFlags().BoolVarP(&conf.Debug, "debug", "d", false, "Enable debugging") rootCmd.PersistentFlags().BoolVarP(&conf.Debug, "debug", "d", false, "Enable debugging")
rootCmd.PersistentFlags().BoolVarP(&conf.NoNumbering, "no-numbering", "n", false, "Disable header numbering") rootCmd.PersistentFlags().BoolVarP(&conf.NoNumbering, "no-numbering", "n", false, "Disable header numbering")
rootCmd.PersistentFlags().BoolVarP(&conf.NoHeaders, "no-headers", "", false, "Disable header display")
rootCmd.PersistentFlags().BoolVarP(&conf.NoColor, "no-color", "N", false, "Disable pattern highlighting") rootCmd.PersistentFlags().BoolVarP(&conf.NoColor, "no-color", "N", false, "Disable pattern highlighting")
rootCmd.PersistentFlags().BoolVarP(&ShowVersion, "version", "V", false, "Print program version") rootCmd.PersistentFlags().BoolVarP(&ShowVersion, "version", "V", false, "Print program version")
rootCmd.PersistentFlags().BoolVarP(&conf.InvertMatch, "invert-match", "v", false, "select non-matching rows") rootCmd.PersistentFlags().BoolVarP(&conf.InvertMatch, "invert-match", "v", false, "select non-matching rows")

View File

@@ -13,6 +13,7 @@ SYNOPSIS
-v, --invert-match select non-matching rows -v, --invert-match select non-matching rows
-n, --no-numbering Disable header numbering -n, --no-numbering Disable header numbering
-N, --no-color Disable pattern highlighting -N, --no-color Disable pattern highlighting
--no-headers Disable headers display
-s, --separator string Custom field separator -s, --separator string Custom field separator
-k, --sort-by int Sort by column (default: 1) -k, --sort-by int Sort by column (default: 1)
@@ -87,6 +88,11 @@ DESCRIPTION
The numbering can be suppressed by using the -n option. The numbering can be suppressed by using the -n option.
By default tablizer shows a header containing the names of each column.
This can be disabled using the --no-headers option. Be aware that this
only affects tabular output modes. Shell, Extended, Yaml and CSV output
modes always use the column names.
By default, if a pattern has been speficied, matches will be By default, if a pattern has been speficied, matches will be
highlighted. You can disable this behavior with the -N option. highlighted. You can disable this behavior with the -N option.
@@ -293,6 +299,7 @@ Operational Flags:
-v, --invert-match select non-matching rows -v, --invert-match select non-matching rows
-n, --no-numbering Disable header numbering -n, --no-numbering Disable header numbering
-N, --no-color Disable pattern highlighting -N, --no-color Disable pattern highlighting
--no-headers Disable headers display
-s, --separator string Custom field separator -s, --separator string Custom field separator
-k, --sort-by int Sort by column (default: 1) -k, --sort-by int Sort by column (default: 1)

View File

@@ -75,7 +75,9 @@ func printOrgmodeData(w io.Writer, c cfg.Config, data *Tabdata) {
tableString := &strings.Builder{} tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString) table := tablewriter.NewWriter(tableString)
if !c.NoHeaders {
table.SetHeader(data.headers) table.SetHeader(data.headers)
}
for _, row := range data.entries { for _, row := range data.entries {
table.Append(trimRow(row)) table.Append(trimRow(row))
@@ -110,7 +112,9 @@ func printMarkdownData(w io.Writer, c cfg.Config, data *Tabdata) {
tableString := &strings.Builder{} tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString) table := tablewriter.NewWriter(tableString)
if !c.NoHeaders {
table.SetHeader(data.headers) table.SetHeader(data.headers)
}
for _, row := range data.entries { for _, row := range data.entries {
table.Append(trimRow(row)) table.Append(trimRow(row))
@@ -130,13 +134,11 @@ func printAsciiData(w io.Writer, c cfg.Config, data *Tabdata) {
tableString := &strings.Builder{} tableString := &strings.Builder{}
table := tablewriter.NewWriter(tableString) table := tablewriter.NewWriter(tableString)
if !c.NoHeaders {
table.SetHeader(data.headers) table.SetHeader(data.headers)
}
table.AppendBulk(data.entries) table.AppendBulk(data.entries)
// for _, row := range data.entries {
// table.Append(trimRow(row))
// }
table.SetAutoWrapText(false) table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true) table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT) table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)

View File

@@ -133,7 +133,7 @@
.\" ======================================================================== .\" ========================================================================
.\" .\"
.IX Title "TABLIZER 1" .IX Title "TABLIZER 1"
.TH TABLIZER 1 "2023-01-23" "1" "User Commands" .TH TABLIZER 1 "2023-04-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
@@ -151,6 +151,7 @@ tablizer \- Manipulate tabular output of other programs
\& \-v, \-\-invert\-match select non\-matching rows \& \-v, \-\-invert\-match select non\-matching rows
\& \-n, \-\-no\-numbering Disable header numbering \& \-n, \-\-no\-numbering Disable header numbering
\& \-N, \-\-no\-color Disable pattern highlighting \& \-N, \-\-no\-color Disable pattern highlighting
\& \-\-no\-headers Disable headers display
\& \-s, \-\-separator string Custom field separator \& \-s, \-\-separator string Custom field separator
\& \-k, \-\-sort\-by int Sort by column (default: 1) \& \-k, \-\-sort\-by int Sort by column (default: 1)
\& \&
@@ -234,6 +235,11 @@ the original order.
.PP .PP
The numbering can be suppressed by using the \fB\-n\fR option. The numbering can be suppressed by using the \fB\-n\fR option.
.PP .PP
By default tablizer shows a header containing the names of each
column. This can be disabled using the \fB\-\-no\-headers\fR option. Be
aware that this only affects tabular output modes. Shell, Extended,
Yaml and \s-1CSV\s0 output modes always use the column names.
.PP
By default, if a \fBpattern\fR has been speficied, matches will be By default, if a \fBpattern\fR has been speficied, matches will be
highlighted. You can disable this behavior with the \fB\-N\fR option. highlighted. You can disable this behavior with the \fB\-N\fR option.
.PP .PP

View File

@@ -12,6 +12,7 @@ tablizer - Manipulate tabular output of other programs
-v, --invert-match select non-matching rows -v, --invert-match select non-matching rows
-n, --no-numbering Disable header numbering -n, --no-numbering Disable header numbering
-N, --no-color Disable pattern highlighting -N, --no-color Disable pattern highlighting
--no-headers Disable headers display
-s, --separator string Custom field separator -s, --separator string Custom field separator
-k, --sort-by int Sort by column (default: 1) -k, --sort-by int Sort by column (default: 1)
@@ -90,6 +91,11 @@ the original order.
The numbering can be suppressed by using the B<-n> option. The numbering can be suppressed by using the B<-n> option.
By default tablizer shows a header containing the names of each
column. This can be disabled using the B<--no-headers> option. Be
aware that this only affects tabular output modes. Shell, Extended,
Yaml and CSV output modes always use the column names.
By default, if a B<pattern> has been speficied, matches will be By default, if a B<pattern> has been speficied, matches will be
highlighted. You can disable this behavior with the B<-N> option. highlighted. You can disable this behavior with the B<-N> option.