Skip to content

Commit

Permalink
feat: override a path to config file in4it#5
Browse files Browse the repository at this point in the history
  • Loading branch information
no committed Mar 16, 2023
1 parent 0c8238c commit 779251f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"log"
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -55,9 +56,14 @@ func init() {
}

func LoadConfig(path string) (config Config, err error) {
viper.AddConfigPath(path)
viper.SetConfigName("config")
viper.SetConfigType("yaml")
userDefinedConfigFile := os.Getenv("ONELOGIN_AUTH_CLI_CONFIG_FILE")
if userDefinedConfigFile != "" {
viper.SetConfigFile(userDefinedConfigFile)
} else {
viper.AddConfigPath(path)
viper.SetConfigName("config")
viper.SetConfigType("yaml")
}

viper.AutomaticEnv()

Expand Down

0 comments on commit 779251f

Please sign in to comment.