From b41df31e14f29a13d2ae4b92563d74719da9247c Mon Sep 17 00:00:00 2001 From: Erik Ostien Date: Fri, 26 Jan 2024 11:35:46 -0700 Subject: [PATCH] Use viper.SafeWriteConfig to init empty config file if needed. Used for github actions tests --- cmd/root.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 8cdba01..e20411b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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