mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 15:47:21 +00:00
core, cmd: removed tablewriter from the dependencies (#33218)
Fix #33212. This PR remove `github.com/olekukonko/tablewriter` from dependencies and use a naive stub implementation. `github.com/olekukonko/tablewriter` is used to format database inspection output neatly. However, it requires custom adjustments for TinyGo and is incompatible with the latest version. --------- Co-authored-by: MariusVanDerWijden <m.vanderwijden@live.de>
This commit is contained in:
parent
f8e5b53f88
commit
495a1d2b1a
9 changed files with 16 additions and 66 deletions
|
|
@ -41,7 +41,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,7 +759,7 @@ 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 := rawdb.NewTableWriter(os.Stdout)
|
||||
table.SetHeader([]string{"Field", "Value"})
|
||||
table.AppendBulk(data)
|
||||
table.Render()
|
||||
|
|
|
|||
|
|
@ -28,11 +28,8 @@ require (
|
|||
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
|
||||
github.com/holiman/uint256 v1.3.2 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
||||
github.com/minio/sha256-simd v1.0.0 // indirect
|
||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||
github.com/rivo/uniseg v0.2.0 // indirect
|
||||
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
|
||||
github.com/supranational/blst v0.3.16-0.20250831170142-f48500c1fdbe // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.12 // indirect
|
||||
|
|
|
|||
|
|
@ -80,17 +80,12 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
|
|||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||
github.com/leanovate/gopter v0.2.11 h1:vRjThO1EKPb/1NsDXuDrzldR28RLkBflWYcU9CvzWu4=
|
||||
github.com/leanovate/gopter v0.2.11/go.mod h1:aK3tzZP/C+p1m3SPRE4SYZFGP7jjkuSI4f7Xvpt0S9c=
|
||||
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=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
|
||||
github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g=
|
||||
github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM=
|
||||
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
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/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
|
@ -105,8 +100,6 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf
|
|||
github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY=
|
||||
github.com/prysmaticlabs/gohashtree v0.0.4-beta h1:H/EbCuXPeTV3lpKeXGPpEV9gsUpkqOOVnWapUyeWro4=
|
||||
github.com/prysmaticlabs/gohashtree v0.0.4-beta/go.mod h1:BFdtALS+Ffhg3lGQIHv9HDWuHS8cTvHZzrHWxwOtGOs=
|
||||
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible h1:Bn1aCHHRnjv4Bl16T8rcaFjYSrGrIZvpiGO6P3Q4GpU=
|
||||
|
|
|
|||
|
|
@ -650,7 +650,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
|||
total.Add(uint64(ancient.size()))
|
||||
}
|
||||
|
||||
table := newTableWriter(os.Stdout)
|
||||
table := NewTableWriter(os.Stdout)
|
||||
table.SetHeader([]string{"Database", "Category", "Size", "Items"})
|
||||
table.SetFooter([]string{"", "Total", common.StorageSize(total.Load()).String(), fmt.Sprintf("%d", count.Load())})
|
||||
table.AppendBulk(stats)
|
||||
|
|
|
|||
|
|
@ -14,10 +14,7 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// TODO: naive stub implementation for tablewriter
|
||||
|
||||
//go:build tinygo
|
||||
// +build tinygo
|
||||
// Naive stub implementation for tablewriter
|
||||
|
||||
package rawdb
|
||||
|
||||
|
|
@ -40,7 +37,7 @@ type Table struct {
|
|||
rows [][]string
|
||||
}
|
||||
|
||||
func newTableWriter(w io.Writer) *Table {
|
||||
func NewTableWriter(w io.Writer) *Table {
|
||||
return &Table{out: w}
|
||||
}
|
||||
|
||||
|
|
@ -89,6 +86,7 @@ func (t *Table) render() error {
|
|||
rowSeparator := t.buildRowSeparator(widths)
|
||||
|
||||
if len(t.headers) > 0 {
|
||||
fmt.Fprintln(t.out, rowSeparator)
|
||||
t.printRow(t.headers, widths)
|
||||
fmt.Fprintln(t.out, rowSeparator)
|
||||
}
|
||||
|
|
@ -100,6 +98,7 @@ func (t *Table) render() error {
|
|||
if len(t.footer) > 0 {
|
||||
fmt.Fprintln(t.out, rowSeparator)
|
||||
t.printRow(t.footer, widths)
|
||||
fmt.Fprintln(t.out, rowSeparator)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -172,21 +171,22 @@ func (t *Table) calculateColumnWidths() []int {
|
|||
//
|
||||
// It generates a string with dashes (-) for each column width, joined by plus signs (+).
|
||||
//
|
||||
// Example output: "----------+--------+-----------"
|
||||
// Example output: "+----------+--------+-----------+"
|
||||
func (t *Table) buildRowSeparator(widths []int) string {
|
||||
parts := make([]string, len(widths))
|
||||
for i, w := range widths {
|
||||
parts[i] = strings.Repeat("-", w)
|
||||
}
|
||||
return strings.Join(parts, "+")
|
||||
return "+" + strings.Join(parts, "+") + "+"
|
||||
}
|
||||
|
||||
// printRow outputs a single row to the table writer.
|
||||
//
|
||||
// Each cell is padded with spaces and separated by pipe characters (|).
|
||||
//
|
||||
// Example output: " Database | Size | Items "
|
||||
// Example output: "| Database | Size | Items |"
|
||||
func (t *Table) printRow(row []string, widths []int) {
|
||||
fmt.Fprintf(t.out, "|")
|
||||
for i, cell := range row {
|
||||
if i > 0 {
|
||||
fmt.Fprint(t.out, "|")
|
||||
|
|
@ -204,5 +204,6 @@ func (t *Table) printRow(row []string, widths []int) {
|
|||
|
||||
fmt.Fprintf(t.out, "%s%s%s", leftPadding, cell, rightPadding)
|
||||
}
|
||||
fmt.Fprintf(t.out, "|")
|
||||
fmt.Fprintln(t.out)
|
||||
}
|
||||
|
|
@ -14,9 +14,6 @@
|
|||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build tinygo
|
||||
// +build tinygo
|
||||
|
||||
package rawdb
|
||||
|
||||
import (
|
||||
|
|
@ -27,7 +24,7 @@ import (
|
|||
|
||||
func TestTableWriterTinyGo(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
table := newTableWriter(&buf)
|
||||
table := NewTableWriter(&buf)
|
||||
|
||||
headers := []string{"Database", "Size", "Items", "Status"}
|
||||
rows := [][]string{
|
||||
|
|
@ -51,7 +48,7 @@ func TestTableWriterValidationErrors(t *testing.T) {
|
|||
// Test missing headers
|
||||
t.Run("MissingHeaders", func(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
table := newTableWriter(&buf)
|
||||
table := NewTableWriter(&buf)
|
||||
|
||||
rows := [][]string{{"x", "y", "z"}}
|
||||
|
||||
|
|
@ -66,7 +63,7 @@ func TestTableWriterValidationErrors(t *testing.T) {
|
|||
|
||||
t.Run("NotEnoughRowColumns", func(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
table := newTableWriter(&buf)
|
||||
table := NewTableWriter(&buf)
|
||||
|
||||
headers := []string{"A", "B", "C"}
|
||||
badRows := [][]string{
|
||||
|
|
@ -85,7 +82,7 @@ func TestTableWriterValidationErrors(t *testing.T) {
|
|||
|
||||
t.Run("TooManyRowColumns", func(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
table := newTableWriter(&buf)
|
||||
table := NewTableWriter(&buf)
|
||||
|
||||
headers := []string{"A", "B", "C"}
|
||||
badRows := [][]string{
|
||||
|
|
@ -105,7 +102,7 @@ func TestTableWriterValidationErrors(t *testing.T) {
|
|||
// Test mismatched footer columns
|
||||
t.Run("MismatchedFooterColumns", func(t *testing.T) {
|
||||
var buf bytes.Buffer
|
||||
table := newTableWriter(&buf)
|
||||
table := NewTableWriter(&buf)
|
||||
|
||||
headers := []string{"A", "B", "C"}
|
||||
rows := [][]string{{"x", "y", "z"}}
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
// Copyright 2025 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//go:build !tinygo
|
||||
// +build !tinygo
|
||||
|
||||
package rawdb
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// Re-export the real tablewriter types and functions
|
||||
type Table = tablewriter.Table
|
||||
|
||||
func newTableWriter(w io.Writer) *Table {
|
||||
return tablewriter.NewWriter(w)
|
||||
}
|
||||
1
go.mod
1
go.mod
|
|
@ -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
3
go.sum
|
|
@ -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=
|
||||
|
|
|
|||
Loading…
Reference in a new issue