1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
From: Mathias Gibbens <gibmat@debian.org>
Description: Apply updates for the new tablewriter API. Based largely on almost identical changes made to gitaly.
diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go
index ca0bce1..a8f155e 100644
--- a/cmd/yggdrasilctl/main.go
+++ b/cmd/yggdrasilctl/main.go
@@ -14,6 +14,8 @@ import (
"time"
"github.com/olekukonko/tablewriter"
+ "github.com/olekukonko/tablewriter/renderer"
+ "github.com/olekukonko/tablewriter/tw"
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
@@ -129,17 +131,26 @@ func run() int {
return 0
}
- table := tablewriter.NewWriter(os.Stdout)
- table.SetAlignment(tablewriter.ALIGN_LEFT)
- table.SetAutoFormatHeaders(false)
- table.SetCenterSeparator("")
- table.SetColumnSeparator("")
- table.SetRowSeparator("")
- table.SetHeaderLine(false)
- table.SetBorder(false)
- table.SetTablePadding("\t") // pad with tabs
- table.SetNoWhiteSpace(true)
- table.SetAutoWrapText(false)
+ table := tablewriter.NewTable(os.Stdout,
+ tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{
+ Borders: tw.BorderNone,
+ Settings: tw.Settings{
+ Lines: tw.Lines{
+ ShowHeaderLine: tw.Off,
+ },
+ Separators: tw.Separators{
+ BetweenRows: tw.Off,
+ BetweenColumns: tw.Off,
+ },
+ },
+ })),
+ )
+
+ table.Configure(func(cfg *tablewriter.Config) {
+ cfg.Header.Formatting.AutoFormat = tw.Off
+ cfg.Row.Alignment.Global = tw.AlignLeft
+ cfg.Row.Formatting.AutoWrap = tw.WrapNone
+ })
switch strings.ToLower(send.Name) {
case "list":
@@ -147,7 +158,7 @@ func run() int {
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
- table.SetHeader([]string{"Command", "Arguments", "Description"})
+ table.Header([]string{"Command", "Arguments", "Description"})
for _, entry := range resp.List {
for i := range entry.Fields {
entry.Fields[i] = entry.Fields[i] + "=..."
@@ -174,7 +185,7 @@ func run() int {
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
- table.SetHeader([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RTT", "RX", "TX", "Down", "Up", "Pr", "Cost", "Last Error"})
+ table.Header([]string{"URI", "State", "Dir", "IP Address", "Uptime", "RTT", "RX", "TX", "Down", "Up", "Pr", "Cost", "Last Error"})
for _, peer := range resp.Peers {
state, lasterr, dir, rtt, rxr, txr := "Up", "-", "Out", "-", "-", "-"
if !peer.Up {
@@ -219,8 +230,8 @@ func run() int {
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
- //table.SetHeader([]string{"Public Key", "IP Address", "Port", "Rest"})
- table.SetHeader([]string{"Public Key", "IP Address", "Parent", "Sequence"})
+ //table.Header([]string{"Public Key", "IP Address", "Port", "Rest"})
+ table.Header([]string{"Public Key", "IP Address", "Parent", "Sequence"})
for _, tree := range resp.Tree {
table.Append([]string{
tree.PublicKey,
@@ -238,7 +249,7 @@ func run() int {
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
- table.SetHeader([]string{"Public Key", "IP Address", "Path", "Seq"})
+ table.Header([]string{"Public Key", "IP Address", "Path", "Seq"})
for _, p := range resp.Paths {
table.Append([]string{
p.PublicKey,
@@ -254,7 +265,7 @@ func run() int {
if err := json.Unmarshal(recv.Response, &resp); err != nil {
panic(err)
}
- table.SetHeader([]string{"Public Key", "IP Address", "Uptime", "RX", "TX"})
+ table.Header([]string{"Public Key", "IP Address", "Uptime", "RX", "TX"})
for _, p := range resp.Sessions {
table.Append([]string{
p.PublicKey,
@@ -287,7 +298,7 @@ func run() int {
}
return "-"
}
- table.SetHeader([]string{"Name", "Listen Address", "Beacon", "Listen", "Password"})
+ table.Header([]string{"Name", "Listen Address", "Beacon", "Listen", "Password"})
for _, p := range resp.Interfaces {
table.Append([]string{
p.Name,
|