|
|
@@ -13,6 +13,7 @@ import (
|
|
|
var (
|
|
|
host string
|
|
|
projectID uint
|
|
|
+ clusterID uint
|
|
|
)
|
|
|
|
|
|
var configCmd = &cobra.Command{
|
|
|
@@ -41,6 +42,27 @@ var setProjectCmd = &cobra.Command{
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+var setClusterCmd = &cobra.Command{
|
|
|
+ Use: "set-cluster [id]",
|
|
|
+ Args: cobra.ExactArgs(1),
|
|
|
+ Short: "Saves the cluster id in the default configuration",
|
|
|
+ Run: func(cmd *cobra.Command, args []string) {
|
|
|
+ clusterID, err := strconv.ParseUint(args[0], 10, 64)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ color.New(color.FgRed).Printf("An error occurred: %v\n", err)
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
+
|
|
|
+ err = setCluster(uint(clusterID))
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ color.New(color.FgRed).Printf("An error occurred: %v\n", err)
|
|
|
+ os.Exit(1)
|
|
|
+ }
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
var setHostCmd = &cobra.Command{
|
|
|
Use: "set-host [host]",
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
@@ -59,6 +81,7 @@ func init() {
|
|
|
rootCmd.AddCommand(configCmd)
|
|
|
|
|
|
configCmd.AddCommand(setProjectCmd)
|
|
|
+ configCmd.AddCommand(setClusterCmd)
|
|
|
configCmd.AddCommand(setHostCmd)
|
|
|
}
|
|
|
|
|
|
@@ -68,6 +91,12 @@ func setProject(id uint) error {
|
|
|
return viper.WriteConfig()
|
|
|
}
|
|
|
|
|
|
+func setCluster(id uint) error {
|
|
|
+ viper.Set("cluster", id)
|
|
|
+ color.New(color.FgGreen).Printf("Set the current cluster id as %d\n", id)
|
|
|
+ return viper.WriteConfig()
|
|
|
+}
|
|
|
+
|
|
|
func setHost(host string) error {
|
|
|
viper.Set("host", host)
|
|
|
err := viper.WriteConfig()
|
|
|
@@ -83,6 +112,14 @@ func getHost() string {
|
|
|
return viper.GetString("host")
|
|
|
}
|
|
|
|
|
|
+func getClusterID() uint {
|
|
|
+ if clusterID != 0 {
|
|
|
+ return clusterID
|
|
|
+ }
|
|
|
+
|
|
|
+ return viper.GetUint("cluster")
|
|
|
+}
|
|
|
+
|
|
|
func getProjectID() uint {
|
|
|
if projectID != 0 {
|
|
|
return projectID
|