added support for environment variables

This commit is contained in:
2022-10-22 10:21:39 +02:00
parent 975510c86a
commit e54435c2e4
4 changed files with 37 additions and 2 deletions

View File

@@ -2,8 +2,6 @@
- rm printYamlData() log.Fatal(), maybe return error on all printers?
- printShellData() checks Columns unnecessarily (compare to yaml or extended)
## Features to be implemented
- add output mode csv

View File

@@ -19,6 +19,7 @@ package cfg
import (
"fmt"
"github.com/gookit/color"
"os"
)
const DefaultSeparator string = `(\s\s+|\t)`
@@ -133,3 +134,21 @@ func (conf *Config) PrepareModeFlags(flag Modeflag) {
conf.OutputMode = Ascii
}
}
func (c *Config) CheckEnv() {
// check for environment vars, command line flags have precedence,
// NO_COLOR is being checked by the color module itself.
if !c.NoNumbering {
_, set := os.LookupEnv("T_NO_HEADER_NUMBERING")
if set {
c.NoNumbering = true
}
}
if len(c.Columns) == 0 {
cols := os.Getenv("T_COLUMNS")
if len(cols) > 1 {
c.Columns = cols
}
}
}

View File

@@ -70,6 +70,7 @@ func Execute() {
}
// prepare flags
conf.CheckEnv()
conf.PrepareModeFlags(modeflag)
conf.PrepareSortFlags(sortmode)

View File

@@ -209,6 +209,23 @@ more output modes available: B<orgtbl> which prints an Emacs org-mode
table and B<markdown> which prints a Markdown table and B<yaml>, which
prints yaml encoding.
=head2 ENVIRONMENT VARIABLES
B<tablizer> supports certain environment variables which use can use
to influence program behavior. Commandline flags have always
precedence over environment variables.
=over
=item <T_NO_HEADER_NUMBERING> - disable numbering of header fields, like B<-n>.
=item <T_COLUMNS> - comma separated list of columns to output, like B<-c>
=item <NO_COLORS> - disable colorization of matches, like B<-N>
=back
=head1 BUGS
In order to report a bug, unexpected behavior, feature requests