From 7285492815c41e39c47fcc50bb78ab9465392b88 Mon Sep 17 00:00:00 2001 From: David Allen Date: Tue, 13 Aug 2024 14:44:11 -0600 Subject: [PATCH] Fixed root persistent flags not binding correctly --- cmd/crawl.go | 5 +++++ cmd/root.go | 13 ++++++------- cmd/update.go | 3 +-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/crawl.go b/cmd/crawl.go index 4dab37d..c7f60bf 100644 --- a/cmd/crawl.go +++ b/cmd/crawl.go @@ -9,6 +9,7 @@ import ( "github.com/OpenCHAMI/magellan/pkg/crawler" "github.com/spf13/cobra" + "github.com/spf13/viper" ) // The `crawl` command walks a collection of Redfish endpoints to collect @@ -66,5 +67,9 @@ func init() { crawlCmd.Flags().StringP("password", "p", "", "Set the password for the BMC") crawlCmd.Flags().BoolP("insecure", "i", false, "Ignore SSL errors") + viper.BindPFlag("crawl.username", crawlCmd.Flags().Lookup("username")) + viper.BindPFlag("crawl.password", crawlCmd.Flags().Lookup("password")) + viper.BindPFlag("crawl.insecure", crawlCmd.Flags().Lookup("insecure")) + rootCmd.AddCommand(crawlCmd) } diff --git a/cmd/root.go b/cmd/root.go index e9a497f..b21e22d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -83,13 +83,12 @@ func init() { rootCmd.PersistentFlags().StringVar(&cachePath, "cache", fmt.Sprintf("/tmp/%s/magellan/assets.db", currentUser.Username), "set the scanning result cache path") // bind viper config flags with cobra - checkBindFlagError(viper.BindPFlag("concurrency", rootCmd.Flags().Lookup("concurrency"))) - checkBindFlagError(viper.BindPFlag("timeout", rootCmd.Flags().Lookup("timeout"))) - checkBindFlagError(viper.BindPFlag("verbose", rootCmd.Flags().Lookup("verbose"))) - checkBindFlagError(viper.BindPFlag("debug", rootCmd.Flags().Lookup("debug"))) - checkBindFlagError(viper.BindPFlag("access-token", rootCmd.Flags().Lookup("verbose"))) - checkBindFlagError(viper.BindPFlag("cache", rootCmd.Flags().Lookup("cache"))) - checkBindFlagError(viper.BindPFlags(rootCmd.Flags())) + checkBindFlagError(viper.BindPFlag("concurrency", rootCmd.PersistentFlags().Lookup("concurrency"))) + checkBindFlagError(viper.BindPFlag("timeout", rootCmd.PersistentFlags().Lookup("timeout"))) + checkBindFlagError(viper.BindPFlag("verbose", rootCmd.PersistentFlags().Lookup("verbose"))) + checkBindFlagError(viper.BindPFlag("debug", rootCmd.PersistentFlags().Lookup("debug"))) + checkBindFlagError(viper.BindPFlag("access-token", rootCmd.PersistentFlags().Lookup("verbose"))) + checkBindFlagError(viper.BindPFlag("cache", rootCmd.PersistentFlags().Lookup("cache"))) } func checkBindFlagError(err error) { diff --git a/cmd/update.go b/cmd/update.go index 9c30a31..c4e04c6 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -88,8 +88,7 @@ func init() { checkBindFlagError(viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username"))) checkBindFlagError(viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password"))) - checkBindFlagError(viper.BindPFlag("update.transfer-protocol", updateCmd.Flags().Lookup("transfer-protocol"))) - checkBindFlagError(viper.BindPFlag("update.protocol", updateCmd.Flags().Lookup("protocol"))) + checkBindFlagError(viper.BindPFlag("update.scheme", updateCmd.Flags().Lookup("scheme"))) checkBindFlagError(viper.BindPFlag("update.firmware.url", updateCmd.Flags().Lookup("firmware.url"))) checkBindFlagError(viper.BindPFlag("update.firmware.version", updateCmd.Flags().Lookup("firmware.version"))) checkBindFlagError(viper.BindPFlag("update.component", updateCmd.Flags().Lookup("component")))