printer_table.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. v3 "go.etcd.io/etcd/clientv3"
  18. "go.etcd.io/etcd/clientv3/snapshot"
  19. "github.com/olekukonko/tablewriter"
  20. )
  21. type tablePrinter struct{ printer }
  22. func (tp *tablePrinter) MemberList(r v3.MemberListResponse) {
  23. hdr, rows := makeMemberListTable(r)
  24. table := tablewriter.NewWriter(os.Stdout)
  25. table.SetHeader(hdr)
  26. for _, row := range rows {
  27. table.Append(row)
  28. }
  29. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  30. table.Render()
  31. }
  32. func (tp *tablePrinter) EndpointHealth(r []epHealth) {
  33. hdr, rows := makeEndpointHealthTable(r)
  34. table := tablewriter.NewWriter(os.Stdout)
  35. table.SetHeader(hdr)
  36. for _, row := range rows {
  37. table.Append(row)
  38. }
  39. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  40. table.Render()
  41. }
  42. func (tp *tablePrinter) EndpointStatus(r []epStatus) {
  43. hdr, rows := makeEndpointStatusTable(r)
  44. table := tablewriter.NewWriter(os.Stdout)
  45. table.SetHeader(hdr)
  46. for _, row := range rows {
  47. table.Append(row)
  48. }
  49. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  50. table.Render()
  51. }
  52. func (tp *tablePrinter) EndpointHashKV(r []epHashKV) {
  53. hdr, rows := makeEndpointHashKVTable(r)
  54. table := tablewriter.NewWriter(os.Stdout)
  55. table.SetHeader(hdr)
  56. for _, row := range rows {
  57. table.Append(row)
  58. }
  59. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  60. table.Render()
  61. }
  62. func (tp *tablePrinter) DBStatus(r snapshot.Status) {
  63. hdr, rows := makeDBStatusTable(r)
  64. table := tablewriter.NewWriter(os.Stdout)
  65. table.SetHeader(hdr)
  66. for _, row := range rows {
  67. table.Append(row)
  68. }
  69. table.SetAlignment(tablewriter.ALIGN_RIGHT)
  70. table.Render()
  71. }