Skip to content

Commit

Permalink
Allow override of config file via flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmartin committed Dec 1, 2023
1 parent 68daea0 commit b92356b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions go-trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 {
Expand Down

0 comments on commit b92356b

Please sign in to comment.