From d92beddb256e74f752348b172391028310ff22da Mon Sep 17 00:00:00 2001 From: Joao Zanutto Date: Mon, 1 Apr 2024 13:42:24 -0700 Subject: [PATCH] make config file not required --- cmd/greenmask/cmd/root.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/greenmask/cmd/root.go b/cmd/greenmask/cmd/root.go index bb880e4d..7090d44a 100644 --- a/cmd/greenmask/cmd/root.go +++ b/cmd/greenmask/cmd/root.go @@ -100,9 +100,6 @@ func init() { RootCmd.AddCommand(validate.Cmd) RootCmd.AddCommand(show_transformer.Cmd) - if err := RootCmd.MarkPersistentFlagRequired("config"); err != nil { - log.Fatal().Err(err).Msg("") - } if err := viper.BindPFlag("log.format", RootCmd.PersistentFlags().Lookup("log-format")); err != nil { log.Fatal().Err(err).Msg("") @@ -137,15 +134,15 @@ func init() { func initConfig() { if cfgFile != "" { viper.SetConfigFile(cfgFile) - } else { - return } viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() if err := viper.ReadInConfig(); err != nil { - log.Fatal().Msgf("unable to read configUtils file: %s", err.Error()) + if _, ok := err.(viper.ConfigFileNotFoundError); !ok { + log.Fatal().Msgf("error parsing config file: %s", err.Error()) + } } decoderCfg := func(cfg *mapstructure.DecoderConfig) {