|
|
@@ -11,10 +11,11 @@ import (
|
|
|
|
|
|
// a set of shared flags
|
|
|
var (
|
|
|
- driver string
|
|
|
- host string
|
|
|
- projectID uint
|
|
|
- clusterID uint
|
|
|
+ driver string
|
|
|
+ host string
|
|
|
+ projectID uint
|
|
|
+ registryID uint
|
|
|
+ clusterID uint
|
|
|
)
|
|
|
|
|
|
var configCmd = &cobra.Command{
|
|
|
@@ -64,6 +65,27 @@ var setClusterCmd = &cobra.Command{
|
|
|
},
|
|
|
}
|
|
|
|
|
|
+var setRegistryCmd = &cobra.Command{
|
|
|
+ Use: "set-registry [id]",
|
|
|
+ Args: cobra.ExactArgs(1),
|
|
|
+ Short: "Saves the registry id in the default configuration",
|
|
|
+ Run: func(cmd *cobra.Command, args []string) {
|
|
|
+ registryID, 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 = setRegistry(uint(registryID))
|
|
|
+
|
|
|
+ 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),
|
|
|
@@ -84,6 +106,7 @@ func init() {
|
|
|
configCmd.AddCommand(setProjectCmd)
|
|
|
configCmd.AddCommand(setClusterCmd)
|
|
|
configCmd.AddCommand(setHostCmd)
|
|
|
+ configCmd.AddCommand(setRegistryCmd)
|
|
|
}
|
|
|
|
|
|
func setDriver(driver string) error {
|
|
|
@@ -117,6 +140,12 @@ func setCluster(id uint) error {
|
|
|
return viper.WriteConfig()
|
|
|
}
|
|
|
|
|
|
+func setRegistry(id uint) error {
|
|
|
+ viper.Set("registry", id)
|
|
|
+ color.New(color.FgGreen).Printf("Set the current registry id as %d\n", id)
|
|
|
+ return viper.WriteConfig()
|
|
|
+}
|
|
|
+
|
|
|
func setHost(host string) error {
|
|
|
viper.Set("host", host)
|
|
|
err := viper.WriteConfig()
|
|
|
@@ -140,6 +169,14 @@ func getClusterID() uint {
|
|
|
return viper.GetUint("cluster")
|
|
|
}
|
|
|
|
|
|
+func getRegistryID() uint {
|
|
|
+ if registryID != 0 {
|
|
|
+ return registryID
|
|
|
+ }
|
|
|
+
|
|
|
+ return viper.GetUint("registry")
|
|
|
+}
|
|
|
+
|
|
|
func getProjectID() uint {
|
|
|
if projectID != 0 {
|
|
|
return projectID
|