From c0e498766ff9b146d50fad8225bb5cea2de26421 Mon Sep 17 00:00:00 2001 From: "David J. Allen" Date: Wed, 11 Dec 2024 14:13:51 -0700 Subject: [PATCH] refactor: exported more cmd variables --- cmd/crawl.go | 16 ++++++++-------- cmd/list.go | 8 ++++---- cmd/update.go | 32 ++++++++++++++++---------------- cmd/version.go | 4 ++-- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/cmd/crawl.go b/cmd/crawl.go index f6ee9a9..a5bb56c 100644 --- a/cmd/crawl.go +++ b/cmd/crawl.go @@ -14,7 +14,7 @@ import ( // The `crawl` command walks a collection of Redfish endpoints to collect // specfic inventory detail. This command only expects host names and does // not require a scan to be performed beforehand. -var crawlCmd = &cobra.Command{ +var CrawlCmd = &cobra.Command{ Use: "crawl [uri]", Short: "Crawl a single BMC for inventory information", Long: "Crawl a single BMC for inventory information. This command does NOT store information\n" + @@ -57,13 +57,13 @@ var crawlCmd = &cobra.Command{ } func init() { - crawlCmd.Flags().StringP("username", "u", "", "Set the username for the BMC") - crawlCmd.Flags().StringP("password", "p", "", "Set the password for the BMC") - crawlCmd.Flags().BoolP("insecure", "i", false, "Ignore SSL errors") + CrawlCmd.Flags().StringP("username", "u", "", "Set the username for the BMC") + CrawlCmd.Flags().StringP("password", "p", "", "Set the password for the BMC") + CrawlCmd.Flags().BoolP("insecure", "i", false, "Ignore SSL errors") - checkBindFlagError(viper.BindPFlag("crawl.username", crawlCmd.Flags().Lookup("username"))) - checkBindFlagError(viper.BindPFlag("crawl.password", crawlCmd.Flags().Lookup("password"))) - checkBindFlagError(viper.BindPFlag("crawl.insecure", crawlCmd.Flags().Lookup("insecure"))) + checkBindFlagError(viper.BindPFlag("crawl.username", CrawlCmd.Flags().Lookup("username"))) + checkBindFlagError(viper.BindPFlag("crawl.password", CrawlCmd.Flags().Lookup("password"))) + checkBindFlagError(viper.BindPFlag("crawl.insecure", CrawlCmd.Flags().Lookup("insecure"))) - rootCmd.AddCommand(crawlCmd) + rootCmd.AddCommand(CrawlCmd) } diff --git a/cmd/list.go b/cmd/list.go index 9fc81cd..24945ae 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -19,7 +19,7 @@ var ( // The `list` command provides an easy way to show what was found // and stored in a cache database from a scan. The data that's stored // is what is consumed by the `collect` command with the --cache flag. -var listCmd = &cobra.Command{ +var ListCmd = &cobra.Command{ Use: "list", Short: "List information stored in cache from a scan", Long: "Prints all of the host and associated data found from performing a scan.\n" + @@ -55,7 +55,7 @@ var listCmd = &cobra.Command{ } func init() { - listCmd.Flags().StringVar(&format, "format", "", "Set the output format (json|default)") - listCmd.Flags().BoolVar(&showCache, "cache-info", false, "Show cache information and exit") - rootCmd.AddCommand(listCmd) + ListCmd.Flags().StringVar(&format, "format", "", "Set the output format (json|default)") + ListCmd.Flags().BoolVar(&showCache, "cache-info", false, "Show cache information and exit") + rootCmd.AddCommand(ListCmd) } diff --git a/cmd/update.go b/cmd/update.go index 57f99b8..d0b050c 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -22,7 +22,7 @@ var ( // The `update` command provides an interface to easily update firmware // using Redfish. It also provides a simple way to check the status of // an update in-progress. -var updateCmd = &cobra.Command{ +var UpdateCmd = &cobra.Command{ Use: "update hosts...", Short: "Update BMC node firmware", Long: "Perform an firmware update using Redfish by providing a remote firmware URL and component.\n\n" + @@ -78,21 +78,21 @@ var updateCmd = &cobra.Command{ } func init() { - updateCmd.Flags().StringVar(&username, "username", "", "Set the BMC user") - updateCmd.Flags().StringVar(&password, "password", "", "Set the BMC password") - updateCmd.Flags().StringVar(&transferProtocol, "scheme", "https", "Set the transfer protocol") - updateCmd.Flags().StringVar(&firmwareUrl, "firmware-url", "", "Set the path to the firmware") - updateCmd.Flags().StringVar(&firmwareVersion, "firmware-version", "", "Set the version of firmware to be installed") - updateCmd.Flags().StringVar(&component, "component", "", "Set the component to upgrade (BMC|BIOS)") - updateCmd.Flags().BoolVar(&showStatus, "status", false, "Get the status of the update") + UpdateCmd.Flags().StringVar(&username, "username", "", "Set the BMC user") + UpdateCmd.Flags().StringVar(&password, "password", "", "Set the BMC password") + UpdateCmd.Flags().StringVar(&transferProtocol, "scheme", "https", "Set the transfer protocol") + UpdateCmd.Flags().StringVar(&firmwareUrl, "firmware-url", "", "Set the path to the firmware") + UpdateCmd.Flags().StringVar(&firmwareVersion, "firmware-version", "", "Set the version of firmware to be installed") + UpdateCmd.Flags().StringVar(&component, "component", "", "Set the component to upgrade (BMC|BIOS)") + UpdateCmd.Flags().BoolVar(&showStatus, "status", false, "Get the status of the update") - checkBindFlagError(viper.BindPFlag("update.username", updateCmd.Flags().Lookup("username"))) - checkBindFlagError(viper.BindPFlag("update.password", updateCmd.Flags().Lookup("password"))) - 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"))) - checkBindFlagError(viper.BindPFlag("update.status", updateCmd.Flags().Lookup("status"))) + checkBindFlagError(viper.BindPFlag("update.username", UpdateCmd.Flags().Lookup("username"))) + checkBindFlagError(viper.BindPFlag("update.password", UpdateCmd.Flags().Lookup("password"))) + 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"))) + checkBindFlagError(viper.BindPFlag("update.status", UpdateCmd.Flags().Lookup("status"))) - rootCmd.AddCommand(updateCmd) + rootCmd.AddCommand(UpdateCmd) } diff --git a/cmd/version.go b/cmd/version.go index 921ae81..769af5e 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" ) -var versionCmd = &cobra.Command{ +var VersionCmd = &cobra.Command{ Use: "version", Short: "Print version info and exit", Run: func(cmd *cobra.Command, args []string) { @@ -14,5 +14,5 @@ var versionCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(versionCmd) + rootCmd.AddCommand(VersionCmd) }