From 9a432671fd847f0faa5a5e4d9f9350ae289db2ac Mon Sep 17 00:00:00 2001 From: Rob Playford Date: Wed, 16 Jun 2021 02:52:13 +0100 Subject: [PATCH] fix home directory config not loading (#1282) leverage `viper.SetConfigType("yaml")` to fix issue regarding home directory configuration failing to load. --- README.md | 1 + cobra/cmd/root.go | 1 + cobra/cmd/testdata/root.go.golden | 1 + cobra/tpl/main.go | 1 + 4 files changed, 4 insertions(+) diff --git a/README.md b/README.md index a1b13ddda..3c290f4a4 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,7 @@ func initConfig() { // Search config in home directory with name ".cobra" (without extension). viper.AddConfigPath(home) + viper.SetConfigType("yaml") viper.SetConfigName(".cobra") } diff --git a/cobra/cmd/root.go b/cobra/cmd/root.go index f27ae7e6c..86254c64c 100644 --- a/cobra/cmd/root.go +++ b/cobra/cmd/root.go @@ -67,6 +67,7 @@ func initConfig() { // Search config in home directory with name ".cobra" (without extension). viper.AddConfigPath(home) + viper.SetConfigType("yaml") viper.SetConfigName(".cobra") } diff --git a/cobra/cmd/testdata/root.go.golden b/cobra/cmd/testdata/root.go.golden index be040365b..26dedff74 100644 --- a/cobra/cmd/testdata/root.go.golden +++ b/cobra/cmd/testdata/root.go.golden @@ -73,6 +73,7 @@ func initConfig() { // Search config in home directory with name ".testproject" (without extension). viper.AddConfigPath(home) + viper.SetConfigType("yaml") viper.SetConfigName(".testproject") } diff --git a/cobra/tpl/main.go b/cobra/tpl/main.go index 0b9c6610e..fbb3372b8 100644 --- a/cobra/tpl/main.go +++ b/cobra/tpl/main.go @@ -86,6 +86,7 @@ func initConfig() { // Search config in home directory with name ".{{ .AppName }}" (without extension). viper.AddConfigPath(home) + viper.SetConfigType("yaml") viper.SetConfigName(".{{ .AppName }}") }