Skip to content

Commit

Permalink
set default redirect port, updated config location, added config checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fantasticrabbit committed Oct 25, 2021
1 parent aa97a69 commit cd62f76
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,36 @@ func initConfig() {
viper.SetConfigFile(cfgFile)
} else {
// Search config in home/.config directory with name "clickup.yaml" (without extension).
viper.AddConfigPath(home + "/.config/clickup/")
viper.AddConfigPath(home)
viper.SetConfigType("yaml")
viper.SetConfigName("clickup")
viper.SetConfigName(".clickup")
}

viper.SetEnvPrefix("clickup")
viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
// fmt.Fprintln(os.Stderr, "Using config file")
viper.ReadInConfig()
} else {
}

viper.SetDefault("redirect_port", "4321")

// Check for required config keys:
if idset := viper.IsSet("client_id"); idset == false {
panic("No Client ID provided, check configuration")
}

if secretset := viper.IsSet("client_secret"); secretset == false {
panic("No Client Secret provided, check configuration")
}

if !viper.InConfig("ctoken") {
token, err := internal.GetToken(viper.GetString("client_id"), viper.GetString("client_secret"), "4321")
if err != nil {
fmt.Fprintln(os.Stderr, "auth failed")
}
viper.Set("cToken", token)
viper.WriteConfigAs(home + "/.config/clickup/clickup.yaml")
viper.WriteConfigAs(home + "/.clickup.yaml")
}
}

0 comments on commit cd62f76

Please sign in to comment.