Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

fix: use persistentpre child func to make DEBUG and KNOW_JSON env vars and flags work #126

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions pkg/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down