From b92356b2393473d6ff35ffa193ab06ca4cd14991 Mon Sep 17 00:00:00 2001 From: jdmartin Date: Fri, 1 Dec 2023 14:41:54 -0800 Subject: [PATCH] Allow override of config file via flags. --- go-trace.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/go-trace.go b/go-trace.go index 71afe74..10be5a6 100644 --- a/go-trace.go +++ b/go-trace.go @@ -454,6 +454,21 @@ func main() { flag.BoolVar(&flagVerbose, "v", false, "Show verbose trace results") flag.IntVar(&flagWidth, "w", 120, "Width of the URL tab") + // Load configuration from file, if exists + config, err := loadConfig() + if err != nil { + fmt.Printf("Error loading configuration: %s\n", err) + os.Exit(1) + } + + // Set flag values based on config, or use default values if config is nil + if config != nil { + flagOutputJSON = config.UseJSON + flagTerse = config.AlwaysTerse + flagVerbose = config.AlwaysVerbose + flagWidth = config.Width + } + flag.Parse() args := flag.Args() @@ -478,21 +493,6 @@ func main() { os.Exit(0) } - // Load configuration from file, if exists - config, err := loadConfig() - if err != nil { - fmt.Printf("Error loading configuration: %s\n", err) - os.Exit(1) - } - - // Set flag values based on config, or use default values if config is nil - if config != nil { - flagOutputJSON = config.UseJSON - flagTerse = config.AlwaysTerse - flagVerbose = config.AlwaysVerbose - flagWidth = config.Width - } - // Perform the trace redirectURL, hops, cloudflareStatus, err := followRedirects(url) if err != nil {