aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/cmd/config.go')
-rw-r--r--client/go/cmd/config.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/client/go/cmd/config.go b/client/go/cmd/config.go
new file mode 100644
index 00000000000..2c10eaf8f02
--- /dev/null
+++ b/client/go/cmd/config.go
@@ -0,0 +1,63 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// vespa config command
+// author: bratseth
+
+package cmd
+
+import (
+ "github.com/spf13/cobra"
+ "github.com/spf13/viper"
+ "github.com/vespa-engine/vespa/util"
+ "os"
+ "path/filepath"
+)
+
+func init() {
+ rootCmd.AddCommand(configCmd)
+}
+
+var configCmd = &cobra.Command{
+ Use: "config",
+ Short: "Configure the Vespa command",
+ Long: `TODO`,
+ Run: func(cmd *cobra.Command, args []string) {
+ },
+}
+
+func readConfig() {
+ home, err := os.UserHomeDir()
+ configName := ".vespa"
+ configType := "yaml"
+
+ cobra.CheckErr(err)
+ viper.AddConfigPath(home)
+ viper.SetConfigType(configType)
+ viper.SetConfigName(configName)
+ viper.AutomaticEnv()
+
+ viper.ReadInConfig();
+}
+
+// WIP: Not used yet
+func writeConfig() {
+ //viper.BindPFlag("container-target", rootCmd.PersistentFlags().Lookup("container-target"))
+ //viper.SetDefault("container-target", "http://127.0.0.1:8080")
+
+ home, _ := os.UserHomeDir()
+ configName := ".vespa"
+ configType := "yaml"
+
+ // Viper bug: WriteConfig() will not create the file if missing
+ configPath := filepath.Join(home, configName + "." + configType)
+ _, statErr := os.Stat(configPath)
+ if !os.IsExist(statErr) {
+ if _, createErr := os.Create(configPath); createErr != nil {
+ util.Error("Warning: Can not remember flag parameters: " + createErr.Error())
+ }
+ }
+
+ writeErr := viper.WriteConfig()
+ if writeErr != nil {
+ util.Error("Could not write config:", writeErr.Error())
+ }
+} \ No newline at end of file