From 231d3d6cf69a819320332b3acf7380080b8b37cf Mon Sep 17 00:00:00 2001 From: LandonTClipp Date: Tue, 20 Dec 2022 15:22:21 -0600 Subject: [PATCH] Updating logs --- cmd/mockery.go | 10 ++++++---- cmd/showconfig.go | 7 +++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/cmd/mockery.go b/cmd/mockery.go index 6201e3af..76e0d77f 100644 --- a/cmd/mockery.go +++ b/cmd/mockery.go @@ -134,8 +134,11 @@ func initConfig(baseSearchPath *pathlib.Path, viperObj *viper.Viper) { currentDir := baseSearchPath - for len(currentDir.Parts()) > 1 { + for { viperObj.AddConfigPath(currentDir.String()) + if len(currentDir.Parts()) <= 1 { + break + } currentDir = currentDir.Parent() } @@ -144,9 +147,8 @@ func initConfig(baseSearchPath *pathlib.Path, viperObj *viper.Viper) { } // Note we purposely ignore the error. Don't care if we can't find a config file. - if err := viperObj.ReadInConfig(); err == nil { - fmt.Fprintf(os.Stderr, "Using config file: %s\n", viperObj.ConfigFileUsed()) - } + viperObj.ReadInConfig() + viperObj.Set("config", viperObj.ConfigFileUsed()) } const regexMetadataChars = "\\.+*?()|[]{}^$" diff --git a/cmd/showconfig.go b/cmd/showconfig.go index 14755da9..7ac7d23f 100644 --- a/cmd/showconfig.go +++ b/cmd/showconfig.go @@ -18,6 +18,7 @@ func NewShowConfigCmd() *cobra.Command { This initializes viper and prints out the merged configuration between config files, environment variables, and CLI flags.`, RunE: func(cmd *cobra.Command, args []string) error { + config := &config.Config{} if err := viper.UnmarshalExact(config); err != nil { return errors.Wrapf(err, "failed to unmarshal config") @@ -26,6 +27,12 @@ func NewShowConfigCmd() *cobra.Command { if err != nil { return errors.Wrapf(err, "Failed to marshal yaml") } + log, err := getLogger(config.LogLevel) + if err != nil { + panic(err) + } + log.Info().Msgf("Using config: %s", config.Config) + fmt.Printf("%s", string(out)) return nil },