cmd/geth, core/rawdb: remove tablewriter dependency

This commit is contained in:
wonder olabisi 2025-11-21 18:01:53 +01:00
parent f4817b7a53
commit 9ac68e288c
4 changed files with 54 additions and 14 deletions

View file

@ -26,6 +26,7 @@ import (
"strconv"
"strings"
"syscall"
"text/tabwriter"
"time"
"github.com/ethereum/go-ethereum/cmd/utils"
@ -41,7 +42,6 @@ import (
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/triedb"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
)
@ -760,10 +760,18 @@ func showMetaData(ctx *cli.Context) error {
data = append(data, []string{"headHeader.Root", fmt.Sprintf("%v", h.Root)})
data = append(data, []string{"headHeader.Number", fmt.Sprintf("%d (%#x)", h.Number, h.Number)})
}
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Field", "Value"})
table.AppendBulk(data)
table.Render()
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
// header
fmt.Fprintln(w, "Field\tValue")
// rows
for _, r := range data {
if len(r) >= 2 {
fmt.Fprintf(w, "%s\t%s\n", r[0], r[1])
} else if len(r) == 1 {
fmt.Fprintf(w, "%s\t\n", r[0])
}
}
_ = w.Flush()
return nil
}

View file

@ -20,14 +20,50 @@
package rawdb
import (
"fmt"
"io"
"github.com/olekukonko/tablewriter"
"strings"
"text/tabwriter"
)
// Re-export the real tablewriter types and functions
type Table = tablewriter.Table
// Lightweight internal table writer used instead of the external dependency.
// It provides the small subset of the tablewriter API that the project uses.
type Table struct {
out io.Writer
headers []string
footer []string
rows [][]string
}
func newTableWriter(w io.Writer) *Table {
return tablewriter.NewWriter(w)
return &Table{out: w}
}
func (t *Table) SetHeader(headers []string) {
t.headers = headers
}
func (t *Table) SetFooter(footer []string) {
t.footer = footer
}
func (t *Table) AppendBulk(rows [][]string) {
t.rows = rows
}
// Render prints a simple tab-separated table using text/tabwriter. This
// intentionally prints a compact, readable table for CLI consumption and
// fulfils the small API surface used in the codebase.
func (t *Table) Render() {
w := tabwriter.NewWriter(t.out, 0, 0, 2, ' ', 0)
if len(t.headers) > 0 {
fmt.Fprintln(w, strings.Join(t.headers, "\t"))
}
for _, row := range t.rows {
fmt.Fprintln(w, strings.Join(row, "\t"))
}
if len(t.footer) > 0 {
fmt.Fprintln(w, strings.Join(t.footer, "\t"))
}
_ = w.Flush()
}

1
go.mod
View file

@ -50,7 +50,6 @@ require (
github.com/mattn/go-colorable v0.1.13
github.com/mattn/go-isatty v0.0.20
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
github.com/olekukonko/tablewriter v0.0.5
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
github.com/pion/stun/v2 v2.0.0
github.com/protolambda/bls12-381-util v0.1.0

3
go.sum
View file

@ -257,7 +257,6 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
@ -274,8 +273,6 @@ github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416 h1:shk/vn9oCoOTmwcou
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416/go.mod h1:NBIhNtsFMo3G2szEBne+bO4gS192HuIYRqfvOWb4i1E=
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=