From 6a685e9f78e706f2958ebf698f9d32c7c45bba13 Mon Sep 17 00:00:00 2001 From: Thorsten Klein Date: Wed, 18 Sep 2024 20:57:49 +0200 Subject: [PATCH] fix: use persistentpre child func to make DEBUG and KNOW_JSON env vars and flags work --- pkg/cmd/main.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/cmd/main.go b/pkg/cmd/main.go index 4c2523a..9900afd 100644 --- a/pkg/cmd/main.go +++ b/pkg/cmd/main.go @@ -44,22 +44,21 @@ func (c *Knowledge) Run(cmd *cobra.Command, _ []string) error { return cmd.Help() } -func (c *Knowledge) Customize(cmd *cobra.Command) { - cmd.PersistentPreRun = func(cmd *cobra.Command, _ []string) { - lvl := slog.LevelInfo +func (c *Knowledge) PersistentPre(_ *cobra.Command, _ []string) error { + lvl := slog.LevelInfo - if c.Debug { - lvl = slog.LevelDebug - slog.SetLogLoggerLevel(lvl) - } + if c.Debug { + lvl = slog.LevelDebug + } + slog.SetLogLoggerLevel(lvl) - if c.Json { - slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ - AddSource: false, - Level: lvl, - }))) - } + if c.Json { + slog.SetDefault(slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ + AddSource: false, + Level: lvl, + }))) } + return nil } type Version struct{}