From 8086029b03da57ef45acb0e90313d464d09aecbb Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sun, 10 Mar 2024 21:08:34 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=9A=20Rename=20stdout.config.formatter?= =?UTF-8?q?=20to=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- cmd/root.go | 2 +- config/default.go | 2 +- config/load_test.go | 6 +++--- config/types.go | 2 +- formatters/new.go | 3 +-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index bcf705a..8b4aa0c 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ Each separate output has its own set of configuration. So, replace `which-one` w *This section may change in the near future. We're considering supporting multiple formats.* -- `formatter`: Which formatter to use when outputting data. This value is used by `my-log drop` to output the new entry. +- `format`: Which formatter to use when outputting data. This value is also used by `my-log drop` to output the new entry. ### `[formatters]` diff --git a/cmd/root.go b/cmd/root.go index 7e7bbbd..44de5f0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -50,7 +50,7 @@ func init() { // will be global for your application. rootCmd.PersistentFlags().StringVarP(&config.ConfigPath, "config", "c", config.ConfigPath, "config file") - rootCmd.PersistentFlags().StringToStringVarP(&config.Overrides, "config-value", "v", config.Overrides, "Override config values. Use dot syntax to specify key. E.g. -v output.stdout.config.formatter=json") + rootCmd.PersistentFlags().StringToStringVarP(&config.Overrides, "config-value", "v", config.Overrides, "Override config values. Use dot syntax to specify key. E.g. -v output.stdout.config.format=json") // Cobra also supports local flags, which will only run // when this action is called directly. diff --git a/config/default.go b/config/default.go index 76ef8d2..8f93873 100644 --- a/config/default.go +++ b/config/default.go @@ -28,7 +28,7 @@ dotFolder = true enabled = true [output.stdout.config] # Formatter to use when outputting to stdout -formatter = "plain" +format = "plain" [formatters] diff --git a/config/load_test.go b/config/load_test.go index 51e024e..eab7c94 100644 --- a/config/load_test.go +++ b/config/load_test.go @@ -70,14 +70,14 @@ func TestStdoutMissing(t *testing.T) { } func TestStdoutLoad(t *testing.T) { - os.Setenv("LOG_STDOUT_FORMATTER", "json") - defer os.Unsetenv("LOG_STDOUT_FORMATTER") + os.Setenv("LOG_STDOUT_FORMAT", "json") + defer os.Unsetenv("LOG_STDOUT_FORMAT") os.Setenv("LOG_STDOUT_ENABLED", "true") defer os.Unsetenv("LOG_STDOUT_ENABLED") c, _ := Load() std, en := c.Outputs.Stdout() assert.True(t, en) - assert.Equal(t, "json", std.Formatter) + assert.Equal(t, "json", std.Format) } func TestFormatJson(t *testing.T) { diff --git a/config/types.go b/config/types.go index a950a80..58fb2c4 100644 --- a/config/types.go +++ b/config/types.go @@ -21,7 +21,7 @@ type Output struct { } type Stdout struct { - Formatter string `env:"LOG_STDOUT_FORMATTER" mapstructure:"formatter"` + Format string `env:"LOG_STDOUT_FORMAT" mapstructure:"format"` } type stdoutEnabled struct { diff --git a/formatters/new.go b/formatters/new.go index 37d8a96..3cfdb3c 100644 --- a/formatters/new.go +++ b/formatters/new.go @@ -19,8 +19,7 @@ func Preferred() (f Formatter, err error) { return } std, _ := conf.Outputs.Stdout() - kind := std.Formatter - return New(kind) + return New(std.Format) } func New(kind string) (f Formatter, err error) {