From 7443e59b233f448e0fb20265eff285cb49ee4a46 Mon Sep 17 00:00:00 2001 From: Roy van de Water Date: Mon, 4 Jun 2018 13:21:36 -0700 Subject: [PATCH] Early return instead of a nested if statement --- cmd/root.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 0d90b8359..b13c543b4 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -57,17 +57,17 @@ func init() { // TODO: move config stuff to it's own package func initConfig() { - if err := readConfig(); err != nil { - if err = createConfig(); err != nil { - fmt.Println(err.Error()) - os.Exit(-1) - } - cfgFile = cfgPathDefault - fatalOnError( - "Failed to re-read config after creating a new file", - readConfig(), // reload config after creating it - ) + if err := readConfig(); err == nil { + return } + + fatalOnError("Error creating a new config file", createConfig()) + + cfgFile = cfgPathDefault + fatalOnError( + "Failed to re-read config after creating a new file", + readConfig(), // reload config after creating it + ) } func readConfig() (err error) {