diff --git a/cmd/greenmask/cmd/root.go b/cmd/greenmask/cmd/root.go index bb880e4d..ad00b3a5 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("") @@ -112,13 +109,6 @@ func init() { log.Fatal().Err(err).Msg("") } - if err := viper.BindEnv("log.level", "LOG_LEVEL"); err != nil { - log.Fatal().Err(err).Msg("") - } - if err := viper.BindEnv("log.format", "LOG_FORMAT"); err != nil { - log.Fatal().Err(err).Msg("") - } - RootCmd.InitDefaultCompletionCmd() RootCmd.InitDefaultHelpCmd() RootCmd.InitDefaultVersionFlag() @@ -137,17 +127,14 @@ func init() { func initConfig() { if cfgFile != "" { viper.SetConfigFile(cfgFile) - } else { - return + if err := viper.ReadInConfig(); err != nil { + log.Fatal().Err(err).Msg("error reading from config file") + } } viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) viper.AutomaticEnv() - if err := viper.ReadInConfig(); err != nil { - log.Fatal().Msgf("unable to read configUtils file: %s", err.Error()) - } - decoderCfg := func(cfg *mapstructure.DecoderConfig) { cfg.DecodeHook = mapstructure.ComposeDecodeHookFunc( configUtils.ParamsToByteSliceHookFunc(), @@ -160,4 +147,4 @@ func initConfig() { log.Fatal().Err(err).Msg("") } -} +} \ No newline at end of file