Skip to content

Commit

Permalink
make config file not required
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-zanutto authored Apr 1, 2024
1 parent 7ea7185 commit d92bedd
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 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 Down Expand Up @@ -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) {
Expand Down

0 comments on commit d92bedd

Please sign in to comment.