From 485270f93f351ceb0a41bce787cec0e10af8ab2e Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Thu, 21 Sep 2023 15:23:22 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20read=20auto=20update=20from=20co?= =?UTF-8?q?nfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- cli/config/config.go | 4 ++-- cli/providers/providers.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cli/config/config.go b/cli/config/config.go index e10e01c214..8bedc9c5c9 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -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)") @@ -69,7 +69,7 @@ func getFeatures() cnquery.Features { return cnquery.Features(flags) } -func initConfig() { +func InitViperConfig() { viper.SetConfigType("yaml") Path = strings.TrimSpace(UserProvidedPath) diff --git a/cli/providers/providers.go b/cli/providers/providers.go index 0b27ac3aac..8852bddfe0 100644 --- a/cli/providers/providers.go +++ b/cli/providers/providers.go @@ -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" @@ -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()