printer_table.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.SetAlignment(tablewriter.ALIGN_RIGHT)
  29. table.Render()
  30. }
  31. func (tp *tablePrinter) EndpointHealth(r []epHealth) {
  32. hdr, rows := makeEndpointHealthTable(r)
  33. table := tablewriter.NewWriter(os.Stdout)
  34. table.SetHeader(hdr)
  35. for _, row := range rows {
  36. table.Append(row)
  37. }
  38. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  39. table.Render()
  40. }
  41. func (tp *tablePrinter) EndpointStatus(r []epStatus) {
  42. hdr, rows := makeEndpointStatusTable(r)
  43. table := tablewriter.NewWriter(os.Stdout)
  44. table.SetHeader(hdr)
  45. for _, row := range rows {
  46. table.Append(row)
  47. }
  48. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  49. table.Render()
  50. }
  51. func (tp *tablePrinter) DBStatus(r dbstatus) {
  52. hdr, rows := makeDBStatusTable(r)
  53. table := tablewriter.NewWriter(os.Stdout)
  54. table.SetHeader(hdr)
  55. for _, row := range rows {
  56. table.Append(row)
  57. }
  58. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  59. table.Render()
  60. }