Backend: Upgrade github.com/olekukonko/tablewriter from v0.0.5 to v1.0.7

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2025-06-24 12:48:38 +02:00
parent 982f864cc0
commit a965c32188
12 changed files with 82 additions and 57 deletions

6
go.mod
View file

@ -51,7 +51,7 @@ require (
golang.org/x/image v0.28.0
)
require github.com/olekukonko/tablewriter v0.0.5
require github.com/olekukonko/tablewriter v1.0.7
require github.com/google/uuid v1.6.0
@ -104,6 +104,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsoprea/go-logging v0.0.0-20200710184922-b02d349568dd // indirect
github.com/dsoprea/go-utility/v2 v2.0.0-20221003172846-a3e1774ef349 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-asn1-ber/asn1-ber v1.5.8-0.20250403174932-29230038a667 // indirect
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
@ -126,11 +127,14 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mandykoh/go-parallel v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/olekukonko/errors v1.1.0 // indirect
github.com/olekukonko/ll v0.0.9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/procfs v0.16.0 // indirect

13
go.sum
View file

@ -120,6 +120,8 @@ github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DP
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
github.com/esimov/pigo v1.4.6 h1:wpB9FstbqeGP/CZP+nTR52tUJe7XErq8buG+k4xCXlw=
github.com/esimov/pigo v1.4.6/go.mod h1:uqj9Y3+3IRYhFK071rxz1QYq0ePhA6+R9jrUZavi46M=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
@ -301,9 +303,10 @@ github.com/mandykoh/prism v0.35.3 h1:H9althbP8zJFC+0kuv1EMmSB3/QsAUYwnttKXNmROsI
github.com/mandykoh/prism v0.35.3/go.mod h1:XppnIliS0AUO5YVJvDbU72xot6qY3CmD6IX92ZNnJmg=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
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.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
@ -323,8 +326,12 @@ github.com/muhlemmer/httpforwarded v0.1.0/go.mod h1:yo9czKedo2pdZhoXe+yDkGVbU0TJ
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
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/olekukonko/errors v1.1.0 h1:RNuGIh15QdDenh+hNvKrJkmxxjV4hcS50Db478Ou5sM=
github.com/olekukonko/errors v1.1.0/go.mod h1:ppzxA5jBKcO1vIpCXQ9ZqgDh8iwODz6OXIGKU8r5m4Y=
github.com/olekukonko/ll v0.0.9 h1:Y+1YqDfVkqMWuEQMclsF9HUR5+a82+dxJuL1HHSRpxI=
github.com/olekukonko/ll v0.0.9/go.mod h1:En+sEW0JNETl26+K8eZ6/W4UQ7CYSrrgg/EdIYT2H8g=
github.com/olekukonko/tablewriter v1.0.7 h1:HCC2e3MM+2g72M81ZcJU11uciw6z/p82aEnm4/ySDGw=
github.com/olekukonko/tablewriter v1.0.7/go.mod h1:H428M+HzoUXC6JU2Abj9IT9ooRmdq9CxuDmKMtrOCMs=
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e h1:s2RNOM/IGdY0Y6qfTeUKhDawdHDpK9RGBdx80qN4Ttw=
github.com/orcaman/writerseeker v0.0.0-20200621085525-1d3f536ff85e/go.mod h1:nBdnFKj15wFbf94Rwfq4m30eAcyY9V/IyKAGQFtqkW0=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=

View file

@ -29,7 +29,7 @@ func TestAuthListCommand(t *testing.T) {
assert.Contains(t, output, "alice ")
assert.NotContains(t, output, "bob ")
assert.NotContains(t, output, "visitor ")
assert.NotContains(t, output, "| Preview Token |")
assert.NotContains(t, output, "│ Preview Token │")
})
t.Run("CSV", func(t *testing.T) {
// Run command with test context.
@ -50,8 +50,8 @@ func TestAuthListCommand(t *testing.T) {
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output, "| Session ID |")
assert.Contains(t, output, "| Preview Token |")
assert.Contains(t, output, "│ Session ID │")
assert.Contains(t, output, "│ Preview Token │")
assert.Contains(t, output, "alice ")
assert.NotContains(t, output, "bob ")
assert.NotContains(t, output, "visitor")

View file

@ -26,7 +26,7 @@ func TestClientsListCommand(t *testing.T) {
// Check command output for plausibility.
// t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output, "| Scope |")
assert.Contains(t, output, "│ Role │ Scope │")
assert.Contains(t, output, "Monitoring")
assert.NotContains(t, output, "alice")
assert.NotContains(t, output, "bob")

View file

@ -21,7 +21,7 @@ func TestClientsModCommand(t *testing.T) {
// Check command output for plausibility.
//t.Logf(output0)
assert.NoError(t, err)
assert.Contains(t, output0, "AuthEnabled | true")
assert.Contains(t, output0, "AuthEnabled true")
assert.Contains(t, output0, "oauth2")
// Run command with test context.
@ -38,7 +38,7 @@ func TestClientsModCommand(t *testing.T) {
// Check command output for plausibility.
//t.Logf(output1)
assert.NoError(t, err)
assert.Contains(t, output1, "AuthEnabled | false")
assert.Contains(t, output1, "AuthEnabled false")
// Run command with test context.
output2, err := RunWithTestContext(ClientsModCommand, []string{"mod", "--enable", "cs7pvt5h8rw9aaqj"})
@ -53,7 +53,7 @@ func TestClientsModCommand(t *testing.T) {
// Check command output for plausibility.
//t.Logf(output3)
assert.NoError(t, err)
assert.Contains(t, output3, "AuthEnabled | true")
assert.Contains(t, output3, "│ AuthEnabled │ true ")
})
t.Run("RegenerateSecret", func(t *testing.T) {
// Run command with test context.

View file

@ -2,6 +2,7 @@ package commands
import (
"fmt"
"strings"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
@ -34,13 +35,19 @@ func showConfigOptionsAction(ctx *cli.Context) error {
return err
}
markDown := ctx.Bool("md")
sections := config.OptionsReportSections
j := 0
for i, section := range sections {
fmt.Printf("### %s ###\n\n", section.Title)
if section.Info != "" && ctx.Bool("md") {
if markDown {
fmt.Printf("### %s\n\n", section.Title)
} else {
fmt.Printf("%s\n\n", strings.ToUpper(section.Title))
}
if section.Info != "" && markDown {
fmt.Printf("%s\n\n", section.Info)
}

View file

@ -2,6 +2,7 @@ package commands
import (
"fmt"
"strings"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
@ -34,13 +35,19 @@ func showConfigYamlAction(ctx *cli.Context) error {
return err
}
markDown := ctx.Bool("md")
sections := config.YamlReportSections
j := 0
for i, section := range sections {
fmt.Printf("### %s ###\n\n", section.Title)
if section.Info != "" && ctx.Bool("md") {
if markDown {
fmt.Printf("### %s\n\n", section.Title)
} else {
fmt.Printf("%s\n\n", strings.ToUpper(section.Title))
}
if section.Info != "" && markDown {
fmt.Printf("%s\n\n", section.Info)
}

View file

@ -14,6 +14,6 @@ func TestUsersLegacyCommand(t *testing.T) {
// Check command output for plausibility.
//t.Logf(output)
assert.NoError(t, err)
assert.Contains(t, output, "| ID | UID | Name | User | Email | Admin | Created At |")
assert.Contains(t, output, "│ ID │ UID │ Name │ User │ Email │ Admin │ Created At │")
})
}

View file

@ -43,7 +43,7 @@ func TestUsersCommand(t *testing.T) {
assert.Contains(t, output4, "Johnny")
assert.Contains(t, output4, "admin")
assert.Contains(t, output4, "johnnny@test.de")
assert.Contains(t, output4, "| DeletedAt | <nil>")
assert.Contains(t, output4, "│ DeletedAt │ <nil>")
// Remove John
// Run command with test context.
@ -62,7 +62,7 @@ func TestUsersCommand(t *testing.T) {
assert.Contains(t, output6, "Johnny")
assert.Contains(t, output6, "admin")
assert.Contains(t, output6, "johnnny@test.de")
assert.Contains(t, output6, "| DeletedAt | time.Date")
assert.NotContains(t, output6, "| DeletedAt | <nil>")
assert.Contains(t, output6, "│ DeletedAt │ time.Date")
assert.NotContains(t, output6, "│ DeletedAt │ <nil>")
})
}

View file

@ -8,31 +8,16 @@ import (
// Credentials returns a text-formatted table with credentials.
func Credentials(idName, idValue, secretName, secretValue string) string {
buf := &bytes.Buffer{}
// Set borders.
borders := tablewriter.Border{
Left: true,
Right: true,
Top: true,
Bottom: true,
}
result := &bytes.Buffer{}
table := tablewriter.NewWriter(result)
// Set values.
rows := make([][]string, 2)
rows[0] = []string{idName, secretName}
rows[1] = []string{idValue, secretValue}
// Render table.
table := tablewriter.NewWriter(buf)
_ = table.Bulk(rows)
_ = table.Render()
table.SetRowLine(true)
table.SetAutoWrapText(false)
table.SetHeader(nil)
table.SetBorders(borders)
table.SetCenterSeparator("|")
table.AppendBulk(rows)
table.Render()
return buf.String()
return result.String()
}

View file

@ -5,6 +5,8 @@ import (
"strings"
"github.com/olekukonko/tablewriter"
"github.com/olekukonko/tablewriter/renderer"
"github.com/olekukonko/tablewriter/tw"
)
// MarkdownTable returns a text-formatted table with caption, optionally as valid Markdown,
@ -24,31 +26,43 @@ func MarkdownTable(rows [][]string, cols []string, opt Options) string {
}
}
buf := &bytes.Buffer{}
result := &bytes.Buffer{}
// Set Borders.
borders := tablewriter.Border{
Left: true,
Right: true,
Top: !opt.Valid,
Bottom: !opt.Valid,
var tableRenderer tw.Renderer
var tableConfig tablewriter.Config
if opt.Valid {
tableRenderer = renderer.NewMarkdown()
tableConfig = tablewriter.Config{
Header: tw.CellConfig{Alignment: tw.CellAlignment{Global: tw.AlignLeft}, Formatting: tw.CellFormatting{AutoFormat: -1}},
Row: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
},
}
} else {
tableRenderer = renderer.NewBlueprint()
tableConfig = tablewriter.Config{
Header: tw.CellConfig{Alignment: tw.CellAlignment{Global: tw.AlignCenter}, Formatting: tw.CellFormatting{AutoFormat: -1}},
Row: tw.CellConfig{
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
},
}
}
// RenderFormat.
table := tablewriter.NewWriter(buf)
table := tablewriter.NewTable(result,
tablewriter.WithRenderer(tableRenderer),
tablewriter.WithConfig(tableConfig),
)
// Set Caption.
if opt.Caption != "" {
table.SetCaption(true, opt.Caption)
table.Caption(tw.Caption{Text: opt.Caption})
}
table.SetAutoWrapText(!opt.Valid && !opt.NoWrap)
table.SetAutoFormatHeaders(false)
table.SetHeader(cols)
table.SetBorders(borders)
table.SetCenterSeparator("|")
table.AppendBulk(rows)
table.Render()
table.Header(cols)
_ = table.Bulk(rows)
_ = table.Render()
return buf.String()
return result.String()
}

View file

@ -18,7 +18,8 @@ func TestTable(t *testing.T) {
if err != nil {
t.Fatal(err)
}
assert.Contains(t, result, "| bar | b & a | z |")
// fmt.Println(result)
assert.Contains(t, result, "│ bar │ b & a | z")
})
t.Run("MarkdownTable", func(t *testing.T) {
result, err := RenderFormat(rows, cols, Markdown)