Skip to content

Commit

Permalink
Use viper.SafeWriteConfig to init empty config file if needed. Used f…
Browse files Browse the repository at this point in the history
…or github actions tests
  • Loading branch information
erikostien-pingidentity committed Jan 26, 2024
1 parent d8aedf6 commit b41df31
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ func initConfig() {

// Search config in $home/.pingctl directory with name "config" (without extension).
viper.AddConfigPath(fmt.Sprintf("%s/.pingctl", home))
// Optionally search working directory for config file
viper.AddConfigPath(".")
viper.SetConfigType("yaml")
viper.SetConfigName("config")
// SafeWriteConfig writes current configuration to file only if the file does not exist.
// Use this to create empty configuration file if not present.
viper.SafeWriteConfig()
}

viper.AutomaticEnv() // read in environment variables that match
Expand Down

0 comments on commit b41df31

Please sign in to comment.