Skip to content

Commit e7df3a1

Browse files
authored
Separate flag and config init to fix --version. (#45)
1 parent 198068c commit e7df3a1

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

cmd/init.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ var (
2727
efs embed.FS
2828
)
2929

30-
func initConfig(ko *koanf.Koanf) {
31-
lo.Info("buildstring", "value", buildString)
32-
30+
func initFlags(ko *koanf.Koanf) {
3331
// Command line flags.
3432
f := flag.NewFlagSet("config", flag.ContinueOnError)
3533
f.Usage = func() {
@@ -51,9 +49,13 @@ func initConfig(ko *koanf.Koanf) {
5149

5250
// Load commandline params.
5351
ko.Load(posflag.Provider(f, ".", ko), nil)
52+
}
53+
54+
func initConfig(ko *koanf.Koanf) {
55+
lo.Info("buildstring", "value", buildString)
5456

5557
// Generate new config file.
56-
if ok, _ := f.GetBool("new-config"); ok {
58+
if ok := ko.Bool("new-config"); ok {
5759
if err := generateConfig(); err != nil {
5860
fmt.Println(err)
5961
os.Exit(1)

cmd/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"log/slog"
67
"os"
78
"strings"
@@ -24,13 +25,15 @@ var (
2425
)
2526

2627
func main() {
27-
initConfig(ko)
28+
initFlags(ko)
2829

2930
if ko.Bool("version") {
30-
lo.Info("version", "value", buildString)
31+
fmt.Println(buildString)
3132
os.Exit(0)
3233
}
3334

35+
initConfig(ko)
36+
3437
// Load environment variables and merge into the loaded config.
3538
if err := ko.Load(env.Provider("DUNGBEETLE_", ".", func(s string) string {
3639
return strings.Replace(strings.ToLower(strings.TrimPrefix(s, "DUNGBEETLE_")), "__", ".", -1)

0 commit comments

Comments
 (0)