Skip to content

Commit

Permalink
Merge pull request #47 from joao-zanutto/patch-10
Browse files Browse the repository at this point in the history
make config file not required
  • Loading branch information
wwoytenko committed Apr 4, 2024
2 parents 6086457 + 1edc7bf commit d4ca706
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions cmd/greenmask/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand All @@ -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()
Expand All @@ -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(),
Expand All @@ -160,4 +147,4 @@ func initConfig() {
log.Fatal().Err(err).Msg("")
}

}
}

0 comments on commit d4ca706

Please sign in to comment.