diff --git a/cmd/init.go b/cmd/init.go index 634f5a1..f4e4c5f 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -27,9 +27,7 @@ var ( efs embed.FS ) -func initConfig(ko *koanf.Koanf) { - lo.Info("buildstring", "value", buildString) - +func initFlags(ko *koanf.Koanf) { // Command line flags. f := flag.NewFlagSet("config", flag.ContinueOnError) f.Usage = func() { @@ -51,9 +49,13 @@ func initConfig(ko *koanf.Koanf) { // Load commandline params. ko.Load(posflag.Provider(f, ".", ko), nil) +} + +func initConfig(ko *koanf.Koanf) { + lo.Info("buildstring", "value", buildString) // Generate new config file. - if ok, _ := f.GetBool("new-config"); ok { + if ok := ko.Bool("new-config"); ok { if err := generateConfig(); err != nil { fmt.Println(err) os.Exit(1) diff --git a/cmd/main.go b/cmd/main.go index 4d45fa7..a841966 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log/slog" "os" "strings" @@ -24,13 +25,15 @@ var ( ) func main() { - initConfig(ko) + initFlags(ko) if ko.Bool("version") { - lo.Info("version", "value", buildString) + fmt.Println(buildString) os.Exit(0) } + initConfig(ko) + // Load environment variables and merge into the loaded config. if err := ko.Load(env.Provider("DUNGBEETLE_", ".", func(s string) string { return strings.Replace(strings.ToLower(strings.TrimPrefix(s, "DUNGBEETLE_")), "__", ".", -1)