Skip to content

Commit

Permalink
Remove github.com/rodaine/table dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
cluttrdev committed Feb 19, 2023
1 parent 8243027 commit a21997a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 23 deletions.
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ module github.com/cluttrdev/deepl-go
go 1.19

require (
github.com/rodaine/table v1.1.0
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
golang.org/x/text v0.7.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
require github.com/inconshreveable/mousetrap v1.1.0 // indirect
17 changes: 2 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rodaine/table v1.1.0 h1:/fUlCSdjamMY8VifdQRIu3VWZXYLY7QHFkVorS8NTr4=
github.com/rodaine/table v1.1.0/go.mod h1:Qu3q5wi1jTQD6B6HsP6szie/S4w1QUQ8pq22pz9iL8g=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
55 changes: 55 additions & 0 deletions internal/table.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package table

import (
"fmt"

"github.com/pkg/errors"
)

type Table struct {
Headers []string
Rows [][]string
}

func NewTable(headers ...string) (t *Table) {
return &Table{
Headers: headers,
Rows: make([][]string, 0),
}
}

func (t *Table) AddRow(cols ...string) error {
if len(cols) != len(t.Headers) {
return errors.Errorf("Number of columns (%d) does not match headers (%d)", len(cols), len(t.Headers))
}

t.Rows = append(t.Rows, cols)
return nil
}

func (t *Table) Print() {
colWidths := make([]int, len(t.Headers))

for j, h := range t.Headers {
colWidths[j] = len(h)
}

for _, r := range t.Rows {
for j, c := range r {
if len(c) > colWidths[j] {
colWidths[j] = len(c)
}
}
}

for j, h := range t.Headers {
fmt.Printf("%-*s ", colWidths[j], h)
}
fmt.Println()
for _, r := range t.Rows {
for j, c := range r {
fmt.Printf("%-*s ", colWidths[j], c)
}
fmt.Println()
}
}
6 changes: 3 additions & 3 deletions pkg/cmd/glossaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"log"
"strings"

"github.com/rodaine/table"
"github.com/spf13/cobra"

table "github.com/cluttrdev/deepl-go/internal"
deepl "github.com/cluttrdev/deepl-go/pkg/api"
)

Expand Down Expand Up @@ -117,10 +117,10 @@ var glossaryEntriesCmd = &cobra.Command{
}

func printGlossaries(glossaries []deepl.GlossaryInfo) {
tbl := table.New("Glossary ID", "Name", "Ready", "Source", "Target", "Count", "Created")
tbl := table.NewTable("Glossary ID", "Name", "Ready", "Source", "Target", "Count", "Created")

for _, g := range glossaries {
tbl.AddRow(g.GlossaryId, g.Name, g.Ready, g.SourceLang, g.TargetLang, g.EntryCount, g.CreationTime)
tbl.AddRow(g.GlossaryId, g.Name, fmt.Sprint(g.Ready), g.SourceLang, g.TargetLang, fmt.Sprint(g.EntryCount), g.CreationTime)
}

tbl.Print()
Expand Down

0 comments on commit a21997a

Please sign in to comment.