From e54435c2e40b5aafb1520264e416d8d69f8181f1 Mon Sep 17 00:00:00 2001 From: Thomas von Dein Date: Sat, 22 Oct 2022 10:21:39 +0200 Subject: [PATCH] added support for environment variables --- TODO.md | 2 -- cfg/config.go | 19 +++++++++++++++++++ cmd/root.go | 1 + tablizer.pod | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/TODO.md b/TODO.md index c78da84..896806a 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/cfg/config.go b/cfg/config.go index 7f1c829..a569016 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -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 + } + } +} diff --git a/cmd/root.go b/cmd/root.go index 466c85d..d152ea3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -70,6 +70,7 @@ func Execute() { } // prepare flags + conf.CheckEnv() conf.PrepareModeFlags(modeflag) conf.PrepareSortFlags(sortmode) diff --git a/tablizer.pod b/tablizer.pod index 68235b5..ee73053 100644 --- a/tablizer.pod +++ b/tablizer.pod @@ -209,6 +209,23 @@ more output modes available: B which prints an Emacs org-mode table and B which prints a Markdown table and B, which prints yaml encoding. +=head2 ENVIRONMENT VARIABLES + +B supports certain environment variables which use can use +to influence program behavior. Commandline flags have always +precedence over environment variables. + +=over + +=item - disable numbering of header fields, like B<-n>. + +=item - comma separated list of columns to output, like B<-c> + +=item - disable colorization of matches, like B<-N> + +=back + + =head1 BUGS In order to report a bug, unexpected behavior, feature requests