Skip to content

Commit

Permalink
Tidied up CLI flag names
Browse files Browse the repository at this point in the history
  • Loading branch information
davidallendj committed Jul 17, 2024
1 parent 085a2cf commit 796a67d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
14 changes: 8 additions & 6 deletions cmd/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,25 @@ func init() {
currentUser, _ = user.Current()
collectCmd.PersistentFlags().StringVar(&smd.Host, "host", smd.Host, "set the host to the SMD API")
collectCmd.PersistentFlags().IntVarP(&smd.Port, "port", "p", smd.Port, "set the port to the SMD API")
collectCmd.PersistentFlags().StringVar(&username, "user", "", "set the BMC user")
collectCmd.PersistentFlags().StringVar(&password, "pass", "", "set the BMC password")
collectCmd.PersistentFlags().StringVar(&username, "username", "", "set the BMC user")
collectCmd.PersistentFlags().StringVar(&password, "password", "", "set the BMC password")
collectCmd.PersistentFlags().StringVar(&protocol, "protocol", "https", "set the protocol used to query")
collectCmd.PersistentFlags().StringVarP(&outputPath, "output", "o", fmt.Sprintf("/tmp/%smagellan/data/", currentUser.Username+"/"), "set the path to store collection data")
collectCmd.PersistentFlags().BoolVar(&forceUpdate, "force-update", false, "set flag to force update data sent to SMD")
collectCmd.PersistentFlags().StringVar(&cacertPath, "ca-cert", "", "path to CA cert. (defaults to system CAs)")
collectCmd.PersistentFlags().StringVar(&cacertPath, "cacert", "", "path to CA cert. (defaults to system CAs)")

// set flags to only be used together
collectCmd.MarkFlagsRequiredTogether("user", "pass")

viper.BindPFlag("collect.driver", collectCmd.Flags().Lookup("driver"))
viper.BindPFlag("collect.host", collectCmd.Flags().Lookup("host"))
viper.BindPFlag("collect.port", collectCmd.Flags().Lookup("port"))
viper.BindPFlag("collect.user", collectCmd.Flags().Lookup("user"))
viper.BindPFlag("collect.pass", collectCmd.Flags().Lookup("pass"))
viper.BindPFlag("collect.username", collectCmd.Flags().Lookup("username"))
viper.BindPFlag("collect.password", collectCmd.Flags().Lookup("password"))
viper.BindPFlag("collect.protocol", collectCmd.Flags().Lookup("protocol"))
viper.BindPFlag("collect.output", collectCmd.Flags().Lookup("output"))
viper.BindPFlag("collect.force-update", collectCmd.Flags().Lookup("force-update"))
viper.BindPFlag("collect.ca-cert", collectCmd.Flags().Lookup("secure-tls"))
viper.BindPFlag("collect.cacert", collectCmd.Flags().Lookup("secure-tls"))
viper.BindPFlags(collectCmd.Flags())

rootCmd.AddCommand(collectCmd)
Expand Down
12 changes: 6 additions & 6 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func init() {
updateCmd.Flags().StringVar(&component, "component", "", "set the component to upgrade")
updateCmd.Flags().BoolVar(&status, "status", false, "get the status of the update")

viper.BindPFlag("bmc-host", updateCmd.Flags().Lookup("bmc-host"))
viper.BindPFlag("bmc-port", updateCmd.Flags().Lookup("bmc-port"))
viper.BindPFlag("user", updateCmd.Flags().Lookup("user"))
viper.BindPFlag("pass", updateCmd.Flags().Lookup("pass"))
viper.BindPFlag("host", updateCmd.Flags().Lookup("host"))
viper.BindPFlag("port", updateCmd.Flags().Lookup("port"))
viper.BindPFlag("username", updateCmd.Flags().Lookup("user"))
viper.BindPFlag("password", updateCmd.Flags().Lookup("pass"))
viper.BindPFlag("transfer-protocol", updateCmd.Flags().Lookup("transfer-protocol"))
viper.BindPFlag("protocol", updateCmd.Flags().Lookup("protocol"))
viper.BindPFlag("firmware-url", updateCmd.Flags().Lookup("firmware-url"))
viper.BindPFlag("firmware-version", updateCmd.Flags().Lookup("firmware-version"))
viper.BindPFlag("firmware.url", updateCmd.Flags().Lookup("firmware.url"))
viper.BindPFlag("firmware.version", updateCmd.Flags().Lookup("firmware.version"))
viper.BindPFlag("component", updateCmd.Flags().Lookup("component"))
viper.BindPFlag("secure-tls", updateCmd.Flags().Lookup("secure-tls"))
viper.BindPFlag("status", updateCmd.Flags().Lookup("status"))
Expand Down
19 changes: 10 additions & 9 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ scan:
collect:
# host: smd-host
# port: smd-port
user: "admin"
pass: "password"
username: "admin"
password: "password"
protocol: "https"
output: "/tmp/magellan/data/"
threads: 1
force-update: false
ca-cert: "cacert.pem"
cacert: "cacert.pem"
update:
bmc-host:
bmc-port: 443
user: "admin"
pass: "password"
host:
port: 443
username: "admin"
password: "password"
transfer-protocol: "HTTP"
protocol: "https"
firmware-url:
firmware-version:
firmware:
url:
version:
component:
secure-tls: false
status: false
Expand Down

0 comments on commit 796a67d

Please sign in to comment.