Skip to content

Commit

Permalink
Early return instead of a nested if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
royvandewater committed Jun 4, 2018
1 parent c6a1719 commit 7443e59
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7443e59

Please sign in to comment.