summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2021-08-31 16:11:51 +0200
committerGitHub <noreply@github.com>2021-08-31 16:11:51 +0200
commit4600b2ce77ef3fad8bb7622a7d7363107e077bdd (patch)
tree151e68dd334812980c356fc2c47e60a6134e7afd
parent371836c15a63e120ac5d0ba6c44cc49d85593eea (diff)
parent70a33945026caff031359a4acadbca53b1b081e5 (diff)
Merge pull request #18925 from vespa-engine/mpolden/fix-binding
Fix flag-config binding
-rw-r--r--client/go/cmd/cert.go1
-rw-r--r--client/go/cmd/config.go10
-rw-r--r--client/go/cmd/deploy.go5
-rw-r--r--client/go/cmd/document.go1
-rw-r--r--client/go/cmd/query.go1
-rw-r--r--client/go/cmd/root.go13
-rw-r--r--client/go/cmd/status.go1
-rw-r--r--client/go/cmd/target.go21
8 files changed, 17 insertions, 36 deletions
diff --git a/client/go/cmd/cert.go b/client/go/cmd/cert.go
index a1d4be6b1f5..95111a7a7df 100644
--- a/client/go/cmd/cert.go
+++ b/client/go/cmd/cert.go
@@ -19,7 +19,6 @@ var overwriteCertificate bool
func init() {
rootCmd.AddCommand(certCmd)
certCmd.Flags().BoolVarP(&overwriteCertificate, "force", "f", false, "Force overwrite of existing certificate and private key")
- addApplicationFlag(certCmd)
certCmd.MarkPersistentFlagRequired(applicationFlag)
}
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go
index d62e2b20e5a..ca4e416a172 100644
--- a/client/go/cmd/config.go
+++ b/client/go/cmd/config.go
@@ -22,7 +22,7 @@ const (
configType = "yaml"
)
-var flagToConfigBindings map[string][]*cobra.Command = make(map[string][]*cobra.Command)
+var flagToConfigBindings map[string]*cobra.Command = make(map[string]*cobra.Command)
func init() {
rootCmd.AddCommand(configCmd)
@@ -92,7 +92,7 @@ func configDir(application string) (string, error) {
}
func bindFlagToConfig(option string, command *cobra.Command) {
- flagToConfigBindings[option] = append(flagToConfigBindings[option], command)
+ flagToConfigBindings[option] = command
}
func readConfig() {
@@ -106,10 +106,8 @@ func readConfig() {
viper.SetConfigType(configType)
viper.AddConfigPath(configDir)
viper.AutomaticEnv()
- for option, commands := range flagToConfigBindings {
- for _, command := range commands {
- viper.BindPFlag(option, command.PersistentFlags().Lookup(option))
- }
+ for option, command := range flagToConfigBindings {
+ viper.BindPFlag(option, command.PersistentFlags().Lookup(option))
}
err = viper.ReadInConfig()
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
diff --git a/client/go/cmd/deploy.go b/client/go/cmd/deploy.go
index 5691f453832..211fbe133fc 100644
--- a/client/go/cmd/deploy.go
+++ b/client/go/cmd/deploy.go
@@ -25,11 +25,6 @@ func init() {
rootCmd.AddCommand(deployCmd)
rootCmd.AddCommand(prepareCmd)
rootCmd.AddCommand(activateCmd)
- addTargetFlag(deployCmd)
- addApplicationFlag(deployCmd)
- addTargetFlag(prepareCmd)
- addTargetFlag(activateCmd)
-
deployCmd.PersistentFlags().StringVarP(&zoneArg, zoneFlag, "z", "dev.aws-us-east-1c", "The zone to use for deployment")
}
diff --git a/client/go/cmd/document.go b/client/go/cmd/document.go
index 6af6e36fa52..ccbd86abfe3 100644
--- a/client/go/cmd/document.go
+++ b/client/go/cmd/document.go
@@ -23,7 +23,6 @@ func init() {
rootCmd.AddCommand(documentCmd)
documentCmd.AddCommand(documentPostCmd)
documentCmd.AddCommand(documentGetCmd)
- addTargetFlag(documentCmd)
}
var documentCmd = &cobra.Command{
diff --git a/client/go/cmd/query.go b/client/go/cmd/query.go
index 75aa7a255b9..5143dcf6f36 100644
--- a/client/go/cmd/query.go
+++ b/client/go/cmd/query.go
@@ -17,7 +17,6 @@ import (
func init() {
rootCmd.AddCommand(queryCmd)
- addTargetFlag(queryCmd)
}
var queryCmd = &cobra.Command{
diff --git a/client/go/cmd/root.go b/client/go/cmd/root.go
index 336e1d64ea1..e48bb74c97f 100644
--- a/client/go/cmd/root.go
+++ b/client/go/cmd/root.go
@@ -22,7 +22,14 @@ var (
Use: "vespa",
Short: "A command-line tool for working with Vespa instances",
}
- color aurora.Aurora
+ color aurora.Aurora
+ targetArg string
+ applicationArg string
+)
+
+const (
+ applicationFlag = "application"
+ targetFlag = "target"
)
func configureLogger() {
@@ -34,6 +41,10 @@ func configureLogger() {
func init() {
configureLogger()
cobra.OnInitialize(readConfig)
+ rootCmd.PersistentFlags().StringVarP(&targetArg, targetFlag, "t", "local", "The name or URL of the recipient of this command")
+ rootCmd.PersistentFlags().StringVarP(&applicationArg, applicationFlag, "a", "", "The application to manage")
+ bindFlagToConfig(targetFlag, rootCmd)
+ bindFlagToConfig(applicationFlag, rootCmd)
}
// Execute executes the root command.
diff --git a/client/go/cmd/status.go b/client/go/cmd/status.go
index 8ae6656c114..4d0b44ee826 100644
--- a/client/go/cmd/status.go
+++ b/client/go/cmd/status.go
@@ -16,7 +16,6 @@ func init() {
statusCmd.AddCommand(statusQueryCmd)
statusCmd.AddCommand(statusDocumentCmd)
statusCmd.AddCommand(statusDeployCmd)
- addTargetFlag(statusCmd)
}
var statusCmd = &cobra.Command{
diff --git a/client/go/cmd/target.go b/client/go/cmd/target.go
index 8b0cc4ee51a..d6c01acf5b1 100644
--- a/client/go/cmd/target.go
+++ b/client/go/cmd/target.go
@@ -7,19 +7,10 @@ package cmd
import (
"log"
"strings"
-
- "github.com/spf13/cobra"
)
const (
- applicationFlag = "application"
- targetFlag = "target"
- cloudApi = "https://api.vespa-external.aws.oath.cloud:4443"
-)
-
-var (
- targetArg string
- applicationArg string
+ cloudApi = "https://api.vespa-external.aws.oath.cloud:4443"
)
type target struct {
@@ -36,16 +27,6 @@ const (
documentContext context = 2
)
-func addTargetFlag(command *cobra.Command) {
- command.PersistentFlags().StringVarP(&targetArg, targetFlag, "t", "local", "The name or URL of the recipient of this command")
- bindFlagToConfig(targetFlag, command)
-}
-
-func addApplicationFlag(command *cobra.Command) {
- command.PersistentFlags().StringVarP(&applicationArg, applicationFlag, "a", "", "The application name to use for deployment")
- bindFlagToConfig(applicationFlag, command)
-}
-
func deployTarget() string {
return getTarget(deployContext).deploy
}