Skip to content

Commit

Permalink
feat: add --config flag to allow different config files to be passed
Browse files Browse the repository at this point in the history
  • Loading branch information
redhatrises authored and acornett21 committed Oct 10, 2023
1 parent 7ab81a7 commit 2b9d982
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/preflight/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func rootCmd() *cobra.Command {
}

viper := viper.Instance()
rootCmd.PersistentFlags().String("config", "", "A preflight config file. The default is config.yaml (env: PFLT_CONFIG)")
_ = viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
rootCmd.PersistentFlags().String("logfile", "", "Where the execution logfile will be written. (env: PFLT_LOGFILE)")
_ = viper.BindPFlag("logfile", rootCmd.PersistentFlags().Lookup("logfile"))

Expand Down Expand Up @@ -65,6 +67,10 @@ func initConfig(viper *spfviper.Viper) {
viper.AddConfigPath(".")

configFileUsed = true
if viper.GetString("config") != "" {
viper.SetConfigFile(viper.GetString("config"))
}

if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(spfviper.ConfigFileNotFoundError); ok {
configFileUsed = false
Expand Down

0 comments on commit 2b9d982

Please sign in to comment.