Browse Source

etcdctlv3: use string slice for endpoints

This deprecates 'endpoint' flag to enable etcdctl to parse
multi-endpoints flag.
Gyu-Ho Lee 9 years ago
parent
commit
13025679c3
3 changed files with 9 additions and 8 deletions
  1. 7 6
      etcdctlv3/command/global.go
  2. 1 1
      etcdctlv3/command/make_mirror_command.go
  3. 1 1
      etcdctlv3/main.go

+ 7 - 6
etcdctlv3/command/global.go

@@ -28,8 +28,9 @@ import (
 // GlobalFlags are flags that defined globally
 // GlobalFlags are flags that defined globally
 // and are inherited to all sub-commands.
 // and are inherited to all sub-commands.
 type GlobalFlags struct {
 type GlobalFlags struct {
-	Endpoints string
-	TLS       transport.TLSInfo
+	Endpoints []string
+
+	TLS transport.TLSInfo
 
 
 	OutputFormat string
 	OutputFormat string
 	IsHex        bool
 	IsHex        bool
@@ -38,7 +39,7 @@ type GlobalFlags struct {
 var display printer = &simplePrinter{}
 var display printer = &simplePrinter{}
 
 
 func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
 func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
-	endpoint, err := cmd.Flags().GetString("endpoint")
+	endpoints, err := cmd.Flags().GetStringSlice("endpoints")
 	if err != nil {
 	if err != nil {
 		ExitWithError(ExitError, err)
 		ExitWithError(ExitError, err)
 	}
 	}
@@ -68,10 +69,10 @@ func mustClientFromCmd(cmd *cobra.Command) *clientv3.Client {
 		ExitWithError(ExitBadFeature, errors.New("unsupported output format"))
 		ExitWithError(ExitBadFeature, errors.New("unsupported output format"))
 	}
 	}
 
 
-	return mustClient(endpoint, cert, key, cacert)
+	return mustClient(endpoints, cert, key, cacert)
 }
 }
 
 
-func mustClient(endpoint, cert, key, cacert string) *clientv3.Client {
+func mustClient(endpoints []string, cert, key, cacert string) *clientv3.Client {
 	// set tls if any one tls option set
 	// set tls if any one tls option set
 	var cfgtls *transport.TLSInfo
 	var cfgtls *transport.TLSInfo
 	tls := transport.TLSInfo{}
 	tls := transport.TLSInfo{}
@@ -92,7 +93,7 @@ func mustClient(endpoint, cert, key, cacert string) *clientv3.Client {
 	}
 	}
 
 
 	cfg := clientv3.Config{
 	cfg := clientv3.Config{
-		Endpoints:   []string{endpoint},
+		Endpoints:   endpoints,
 		TLS:         cfgtls,
 		TLS:         cfgtls,
 		DialTimeout: 20 * time.Second,
 		DialTimeout: 20 * time.Second,
 	}
 	}

+ 1 - 1
etcdctlv3/command/make_mirror_command.go

@@ -57,7 +57,7 @@ func makeMirrorCommandFunc(cmd *cobra.Command, args []string) {
 		ExitWithError(ExitBadArgs, errors.New("make-mirror takes one destination arguement."))
 		ExitWithError(ExitBadArgs, errors.New("make-mirror takes one destination arguement."))
 	}
 	}
 
 
-	dc := mustClient(args[0], mmcert, mmkey, mmcacert)
+	dc := mustClient([]string{args[0]}, mmcert, mmkey, mmcacert)
 	c := mustClientFromCmd(cmd)
 	c := mustClientFromCmd(cmd)
 
 
 	err := makeMirror(context.TODO(), c, dc)
 	err := makeMirror(context.TODO(), c, dc)

+ 1 - 1
etcdctlv3/main.go

@@ -41,7 +41,7 @@ var (
 )
 )
 
 
 func init() {
 func init() {
-	rootCmd.PersistentFlags().StringVar(&globalFlags.Endpoints, "endpoint", "127.0.0.1:2378", "gRPC endpoint")
+	rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2378", "127.0.0.1:22378", "127.0.0.1:32378"}, "gRPC endpoints")
 
 
 	rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (simple, json, protobuf)")
 	rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (simple, json, protobuf)")
 	rootCmd.PersistentFlags().BoolVar(&globalFlags.IsHex, "hex", false, "print byte strings as hex encoded strings")
 	rootCmd.PersistentFlags().BoolVar(&globalFlags.IsHex, "hex", false, "print byte strings as hex encoded strings")