printer_table.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package command
  15. import (
  16. "os"
  17. "github.com/olekukonko/tablewriter"
  18. v3 "github.com/coreos/etcd/clientv3"
  19. )
  20. type tablePrinter struct{ printer }
  21. func (tp *tablePrinter) MemberList(r v3.MemberListResponse) {
  22. hdr, rows := makeMemberListTable(r)
  23. table := tablewriter.NewWriter(os.Stdout)
  24. table.SetHeader(hdr)
  25. for _, row := range rows {
  26. table.Append(row)
  27. }
  28. table.Render()
  29. }
  30. func (tp *tablePrinter) EndpointStatus(r []epStatus) {
  31. hdr, rows := makeEndpointStatusTable(r)
  32. table := tablewriter.NewWriter(os.Stdout)
  33. table.SetHeader(hdr)
  34. for _, row := range rows {
  35. table.Append(row)
  36. }
  37. table.Render()
  38. }
  39. func (tp *tablePrinter) DBStatus(r dbstatus) {
  40. hdr, rows := makeDBStatusTable(r)
  41. table := tablewriter.NewWriter(os.Stdout)
  42. table.SetHeader(hdr)
  43. for _, row := range rows {
  44. table.Append(row)
  45. }
  46. table.Render()
  47. }