Skip to content

Commit

Permalink
🐛 read auto update from config
Browse files Browse the repository at this point in the history
We ignored the configured value by default and it only worked from CLI argument. Now it reads the config first and defers to the CLI for overrides.

Signed-off-by: Dominik Richter <[email protected]>
  • Loading branch information
arlimus committed Sep 21, 2023
1 parent 8e36364 commit 485270f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (

// Init initializes and loads the mondoo config
func Init(rootCmd *cobra.Command) {
cobra.OnInitialize(initConfig)
cobra.OnInitialize(InitViperConfig)
Features = getFeatures()
// persistent flags are global for the application
rootCmd.PersistentFlags().StringVar(&UserProvidedPath, "config", "", "Set config file path (default $HOME/.config/mondoo/mondoo.yml)")
Expand Down Expand Up @@ -69,7 +69,7 @@ func getFeatures() cnquery.Features {
return cnquery.Features(flags)
}

func initConfig() {
func InitViperConfig() {
viper.SetConfigType("yaml")

Path = strings.TrimSpace(UserProvidedPath)
Expand Down
8 changes: 7 additions & 1 deletion cli/providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/spf13/pflag"
"github.com/spf13/viper"
"go.mondoo.com/cnquery/cli/components"
"go.mondoo.com/cnquery/cli/config"
"go.mondoo.com/cnquery/llx"
"go.mondoo.com/cnquery/providers"
"go.mondoo.com/cnquery/providers-sdk/v1/plugin"
Expand Down Expand Up @@ -53,8 +54,13 @@ func AttachCLIs(rootCmd *cobra.Command, commands ...*Command) error {
func detectConnectorName(args []string, commands []*Command) (string, bool) {
autoUpdate := true

config.InitViperConfig()
if viper.IsSet("auto_update") {
autoUpdate = viper.GetBool("auto_update")
}

flags := pflag.NewFlagSet("set", pflag.ContinueOnError)
flags.Bool("auto-update", true, "")
flags.Bool("auto-update", autoUpdate, "")
flags.BoolP("help", "h", false, "")

builtins := genBuiltinFlags()
Expand Down

0 comments on commit 485270f

Please sign in to comment.