Browse Source

Merge pull request #5453 from gyuho/protobuf_etcdctlv3

etcdctl/ctlv3: protobuf write-out for member list
Gyu-Ho Lee 9 years ago
parent
commit
d117684086
3 changed files with 18 additions and 5 deletions
  1. 13 0
      etcdctl/READMEv3.md
  2. 4 4
      etcdctl/ctlv3/command/printer.go
  3. 1 1
      etcdctl/ctlv3/ctl.go

+ 13 - 0
etcdctl/READMEv3.md

@@ -419,6 +419,10 @@ On success, prints a humanized table of the member IDs, statuses, names, peer ad
 
 
 On success, prints a JSON listing of the member IDs, statuses, names, peer addresses, and client addresses. On failure, prints an error message and returns with a non-zero exit code.
 On success, prints a JSON listing of the member IDs, statuses, names, peer addresses, and client addresses. On failure, prints an error message and returns with a non-zero exit code.
 
 
+##### Protobuf reply
+
+The protobuf encoding of the MEMBER LIST [RPC response][member_list_rpc].
+
 #### Examples
 #### Examples
 
 
 ```bash
 ```bash
@@ -484,6 +488,10 @@ On success, prints a humanized table of each endpoint URL, ID, version, database
 
 
 On success, prints a line of JSON encoding each endpoint URL, ID, version, database size, leadership status, raft term, and raft status. On failure, returns with a non-zero exit code.
 On success, prints a line of JSON encoding each endpoint URL, ID, version, database size, leadership status, raft term, and raft status. On failure, returns with a non-zero exit code.
 
 
+##### Protobuf reply
+
+ENDPOINT STATUS does not support protobuf encoded output.
+
 #### Examples
 #### Examples
 
 
 ```bash
 ```bash
@@ -715,6 +723,10 @@ On success, prints a humanized table of the database hash, revision, total keys,
 
 
 On success, prints a line of JSON encoding the database hash, revision, total keys, and size. On failure, return with a non-zero exit code.
 On success, prints a line of JSON encoding the database hash, revision, total keys, and size. On failure, return with a non-zero exit code.
 
 
+##### Protobuf reply
+
+SNAPSHOT STATUS does not support protobuf encoded output.
+
 #### Examples
 #### Examples
 ```bash
 ```bash
 ./etcdctl snapshot status file.db
 ./etcdctl snapshot status file.db
@@ -795,6 +807,7 @@ finished transforming keys
 
 
 [etcdrpc]: ../etcdserver/etcdserverpb/rpc.proto
 [etcdrpc]: ../etcdserver/etcdserverpb/rpc.proto
 [storagerpc]: ../mvcc/mvccpb/kv.proto
 [storagerpc]: ../mvcc/mvccpb/kv.proto
+[member_list_rpc]: ../etcdserver/etcdserverpb/rpc.proto#L493-L497
 
 
 ## Compatibility Support
 ## Compatibility Support
 
 

+ 4 - 4
etcdctl/ctlv3/command/printer.go

@@ -275,15 +275,15 @@ func (p *pbPrinter) Alarm(r v3.AlarmResponse) {
 	printPB((*pb.AlarmResponse)(&r))
 	printPB((*pb.AlarmResponse)(&r))
 }
 }
 
 
-func (pb *pbPrinter) MemberList(r v3.MemberListResponse) {
-	ExitWithError(ExitBadFeature, errors.New("only support simple or json as output format"))
+func (p *pbPrinter) MemberList(r v3.MemberListResponse) {
+	printPB((*pb.MemberListResponse)(&r))
 }
 }
 
 
-func (pb *pbPrinter) EndpointStatus(statusList []epStatus) {
+func (p *pbPrinter) EndpointStatus(statusList []epStatus) {
 	ExitWithError(ExitBadFeature, errors.New("only support simple or json as output format"))
 	ExitWithError(ExitBadFeature, errors.New("only support simple or json as output format"))
 }
 }
 
 
-func (pb *pbPrinter) DBStatus(r dbstatus) {
+func (p *pbPrinter) DBStatus(r dbstatus) {
 	ExitWithError(ExitBadFeature, errors.New("only support simple or json as output format"))
 	ExitWithError(ExitBadFeature, errors.New("only support simple or json as output format"))
 }
 }
 
 

+ 1 - 1
etcdctl/ctlv3/ctl.go

@@ -45,7 +45,7 @@ var (
 func init() {
 func init() {
 	rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2379", "127.0.0.1:22379", "127.0.0.1:32379"}, "gRPC endpoints")
 	rootCmd.PersistentFlags().StringSliceVar(&globalFlags.Endpoints, "endpoints", []string{"127.0.0.1:2379", "127.0.0.1:22379", "127.0.0.1:32379"}, "gRPC endpoints")
 
 
-	rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (simple, json, protobuf, table)")
+	rootCmd.PersistentFlags().StringVarP(&globalFlags.OutputFormat, "write-out", "w", "simple", "set the output format (simple, json, etc..)")
 	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")
 
 
 	rootCmd.PersistentFlags().DurationVar(&globalFlags.DialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections")
 	rootCmd.PersistentFlags().DurationVar(&globalFlags.DialTimeout, "dial-timeout", defaultDialTimeout, "dial timeout for client connections")