Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add headers to all tables #8157

Merged
merged 8 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ linters:
issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
- path: _test\.go
linters:
- staticcheck
text: "SA1019: tableprinter.NoHeader is deprecated: use WithHeader unless required otherwise."
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/charmbracelet/glamour v0.6.0
github.com/charmbracelet/lipgloss v0.5.0
github.com/cli/go-gh/v2 v2.3.0
github.com/cli/go-gh/v2 v2.4.1-0.20231019124728-ec1e1cd3e0cb
github.com/cli/oauth v1.0.1
github.com/cli/safeexec v1.0.1
github.com/cpuguy83/go-md2man/v2 v2.0.3
Expand Down Expand Up @@ -51,8 +51,8 @@ require (
github.com/alessio/shellescape v1.4.1 // indirect
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/cli/browser v1.2.0 // indirect
github.com/cli/shurcooL-graphql v0.0.3 // indirect
github.com/cli/browser v1.3.0 // indirect
github.com/cli/shurcooL-graphql v0.0.4 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
Expand Down
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ github.com/charmbracelet/glamour v0.6.0/go.mod h1:taqWV4swIMMbWALc0m7AfE9JkPSU8o
github.com/charmbracelet/lipgloss v0.5.0 h1:lulQHuVeodSgDez+3rGiuxlPVXSnhth442DATR2/8t8=
github.com/charmbracelet/lipgloss v0.5.0/go.mod h1:EZLha/HbzEt7cYqdFPovlqy5FZPj0xFhg5SaqxScmgs=
github.com/cli/browser v1.0.0/go.mod h1:IEWkHYbLjkhtjwwWlwTHW2lGxeS5gezEQBMLTwDHf5Q=
github.com/cli/browser v1.2.0 h1:yvU7e9qf97kZqGFX6n2zJPHsmSObY9ske+iCvKelvXg=
github.com/cli/browser v1.2.0/go.mod h1:xFFnXLVcAyW9ni0cuo6NnrbCP75JxJ0RO7VtCBiH/oI=
github.com/cli/go-gh/v2 v2.3.0 h1:FAQAP4PaWSAJf4VSxFEIYDQ1oBIs+bKB4GXQAiRr2sQ=
github.com/cli/go-gh/v2 v2.3.0/go.mod h1:6WBUuf7LUVAc+eXYYX/nYTYURRc6M03K9cJNwBKvwT0=
github.com/cli/browser v1.3.0 h1:LejqCrpWr+1pRqmEPDGnTZOjsMe7sehifLynZJuqJpo=
github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEfBTk=
github.com/cli/go-gh/v2 v2.4.1-0.20231019124728-ec1e1cd3e0cb h1:HeIpiv5Jf09GQA0AyABbjC7Zq55eyIxpv4/BU6ujHRk=
github.com/cli/go-gh/v2 v2.4.1-0.20231019124728-ec1e1cd3e0cb/go.mod h1:h3salfqqooVpzKmHp6aUdeNx62UmxQRpLbagFSHTJGQ=
github.com/cli/oauth v1.0.1 h1:pXnTFl/qUegXHK531Dv0LNjW4mLx626eS42gnzfXJPA=
github.com/cli/oauth v1.0.1/go.mod h1:qd/FX8ZBD6n1sVNQO3aIdRxeu5LGw9WhKnYhIIoC2A4=
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/cli/safeexec v1.0.1 h1:e/C79PbXF4yYTN/wauC4tviMxEV13BwljGj0N9j+N00=
github.com/cli/safeexec v1.0.1/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/cli/shurcooL-graphql v0.0.3 h1:CtpPxyGDs136/+ZeyAfUKYmcQBjDlq5aqnrDCW5Ghh8=
github.com/cli/shurcooL-graphql v0.0.3/go.mod h1:tlrLmw/n5Q/+4qSvosT+9/W5zc8ZMjnJeYBxSdb4nWA=
github.com/cli/shurcooL-graphql v0.0.4 h1:6MogPnQJLjKkaXPyGqPRXOI2qCsQdqNfUY1QSJu2GuY=
github.com/cli/shurcooL-graphql v0.0.4/go.mod h1:3waN4u02FiZivIV+p1y4d0Jo1jc6BViMA73C+sZo2fk=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -183,7 +183,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220923203811-8be639271d50/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
Expand All @@ -199,7 +198,6 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
24 changes: 5 additions & 19 deletions internal/tableprinter/table_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,21 @@ func NewWithWriter(w io.Writer, isTTY bool, maxWidth int, cs *iostreams.ColorSch
if isTTY && len(headers.columns) > 0 {
// Make sure all headers are uppercase.
for i := range headers.columns {
// TODO: Consider truncating longer headers e.g., NUMBER, or removing unnecessary headers e.g., DESCRIPTION with no descriptions.
headers.columns[i] = strings.ToUpper(headers.columns[i])
}

// Make sure all header columns are padded - even the last one - to apply the proper TableHeader style.
// Checking cs.Enabled() avoids having to do that for nearly all CLI tests.
// Make sure all header columns are padded - even the last one. Previously, the last header column
// was not padded. In tests cs.Enabled() is false which allows us to avoid having to fix up
// numerous tests that verify header padding.
var paddingFunc func(int, string) string
if cs.Enabled() {
paddingFunc = func(width int, text string) string {
if l := len(text); l < width {
return text + strings.Repeat(" ", width-l)
}
return text
}
paddingFunc = text.PadRight
}

tp.AddHeader(
headers.columns,
tableprinter.WithPadding(paddingFunc),
tableprinter.WithColor(cs.TableHeader),
tableprinter.WithColor(cs.GrayUnderline),
)
}

Expand All @@ -103,12 +98,3 @@ func WithHeader(columns ...string) headerOption {
//
// Deprecated: use WithHeader unless required otherwise.
var NoHeader = headerOption{}

// TruncateNonURL truncates any text that does not begin with "https://" or "http://".
// This is provided for backward compatibility with the old table printer for existing tables.
func TruncateNonURL(maxWidth int, s string) string {
if strings.HasPrefix(s, "https://") || strings.HasPrefix(s, "http://") {
return s
}
return text.Truncate(maxWidth, s)
}
47 changes: 0 additions & 47 deletions internal/tableprinter/table_printer_test.go

This file was deleted.

4 changes: 4 additions & 0 deletions internal/text/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func DisplayURL(urlStr string) string {
func RemoveDiacritics(value string) string {
return text.RemoveDiacritics(value)
}

func PadRight(maxWidth int, s string) string {
return text.PadRight(maxWidth, s)
}
2 changes: 1 addition & 1 deletion pkg/cmd/codespace/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (a *App) List(ctx context.Context, opts *listOptions, exporter cmdutil.Expo
}
tp.AddField(text.FuzzyAgoAbbr(time.Now(), ct), tableprinter.WithColor(cs.Gray))
} else {
tp.AddField(c.CreatedAt, nil, nil)
tp.AddField(c.CreatedAt)
}

if hasNonProdVSCSTarget {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/extension/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
t.AddField(repo)
version := displayExtensionVersion(c, c.CurrentVersion())
if c.IsPinned() {
t.AddField(version, nil, tableprinter.WithColor(cs.Cyan))
t.AddField(version, tableprinter.WithColor(cs.Cyan))
} else {
t.AddField(version)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/gist/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func listRun(opts *ListOptions) error {
}

cs := opts.IO.ColorScheme()
tp := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "DESCRIPTION", "FILES", "", "UPDATED"))
tp := tableprinter.New(opts.IO, tableprinter.WithHeader("ID", "DESCRIPTION", "FILES", "VISIBILITY", "UPDATED"))

for _, gist := range gists {
fileCount := len(gist.Files)
Expand All @@ -120,7 +120,6 @@ func listRun(opts *ListOptions) error {
tp.AddField(
text.RemoveExcessiveWhitespace(description),
tableprinter.WithColor(cs.Bold),
tableprinter.WithTruncate(tableprinter.TruncateNonURL),
)
tp.AddField(text.Pluralize(fileCount, "file"))
tp.AddField(visibility, tableprinter.WithColor(visColor))
Expand Down
26 changes: 13 additions & 13 deletions pkg/cmd/gist/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ func Test_listRun(t *testing.T) {
)
},
wantOut: heredoc.Doc(`
ID DESCRIPTION FILES UPDATED
1234567890 cool.txt 1 file public about 6 hours ago
4567890123 1 file public about 6 hours ago
2345678901 tea leaves thwart those who ... 2 files secret about 6 hours ago
3456789012 short desc 11 files secret about 6 hours ago
ID DESCRIPTION FILES VISIBILITY UPDATED
1234567890 cool.txt 1 file public about 6 hours ago
4567890123 1 file public about 6 hours ago
2345678901 tea leaves thwart those ... 2 files secret about 6 hours ago
3456789012 short desc 11 files secret about 6 hours ago
`),
},
{
Expand Down Expand Up @@ -215,9 +215,9 @@ func Test_listRun(t *testing.T) {
)
},
wantOut: heredoc.Doc(`
ID DESCRIPTION FILES UPDATED
1234567890 cool.txt 1 file public about 6 hours ago
4567890123 1 file public about 6 hours ago
ID DESCRIPTION FILES VISIBILITY UPDATED
1234567890 cool.txt 1 file public about 6 hours ago
4567890123 1 file public about 6 hours ago
`),
},
{
Expand Down Expand Up @@ -263,9 +263,9 @@ func Test_listRun(t *testing.T) {
)
},
wantOut: heredoc.Doc(`
ID DESCRIPTION FILES UPDATED
2345678901 tea leaves thwart those who ... 2 files secret about 6 hours ago
3456789012 short desc 11 files secret about 6 hours ago
ID DESCRIPTION FILES VISIBILITY UPDATED
2345678901 tea leaves thwart those ... 2 files secret about 6 hours ago
3456789012 short desc 11 files secret about 6 hours ago
`),
},
{
Expand All @@ -289,8 +289,8 @@ func Test_listRun(t *testing.T) {
)
},
wantOut: heredoc.Doc(`
ID DESCRIPTION FILES UPDATED
1234567890 cool.txt 1 file public about 6 hours ago
ID DESCRIPTION FILES VISIBILITY UPDATED
1234567890 cool.txt 1 file public about 6 hours ago
`),
},
{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/issue/shared/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func PrintIssues(io *iostreams.IOStreams, now time.Time, prefix string, totalCou
if !isTTY {
table.AddField(issue.State)
}
table.AddField(text.RemoveExcessiveWhitespace(issue.Title), tableprinter.WithTruncate(tableprinter.TruncateNonURL))
table.AddField(text.RemoveExcessiveWhitespace(issue.Title))
table.AddField(issueLabelList(&issue, cs, isTTY))
table.AddTimeField(now, issue.UpdatedAt, cs.Gray)
table.EndRow()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/label/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func printLabels(io *iostreams.IOStreams, labels []label) error {

for _, label := range labels {
table.AddField(label.Name, tableprinter.WithColor(cs.ColorFromRGB(label.Color)))
table.AddField(label.Description, tableprinter.WithTruncate(tableprinter.TruncateNonURL))
table.AddField(label.Description)
table.AddField("#" + label.Color)

table.EndRow()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/pr/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func listRun(opts *ListOptions) error {
}

table.AddField(prNum, tableprinter.WithColor(cs.ColorFromString(shared.ColorForPRState(pr))))
table.AddField(text.RemoveExcessiveWhitespace(pr.Title), tableprinter.WithTruncate(tableprinter.TruncateNonURL))
table.AddField(text.RemoveExcessiveWhitespace(pr.Title))
table.AddField(pr.HeadLabel(), tableprinter.WithColor(cs.Cyan))
if !isTTY {
table.AddField(prStateWithDraft(&pr))
Expand Down
4 changes: 4 additions & 0 deletions pkg/cmd/project/field-list/field_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func TestRunList_User(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
number: 1,
Expand Down Expand Up @@ -256,6 +257,7 @@ func TestRunList_Org(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
number: 1,
Expand Down Expand Up @@ -339,6 +341,7 @@ func TestRunList_Me(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
number: 1,
Expand Down Expand Up @@ -406,6 +409,7 @@ func TestRunList_Empty(t *testing.T) {

ios, _, _, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
number: 1,
Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/project/item-list/item_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func TestRunList_User(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
number: 1,
Expand Down Expand Up @@ -285,6 +286,7 @@ func TestRunList_Org(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
number: 1,
Expand Down Expand Up @@ -382,6 +384,7 @@ func TestRunList_Me(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
number: 1,
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/project/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ func TestRunList(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
owner: "monalisa",
Expand Down Expand Up @@ -225,6 +226,7 @@ func TestRunList_Me(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
owner: "@me",
Expand Down Expand Up @@ -296,6 +298,7 @@ func TestRunListViewer(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{},
client: client,
Expand Down Expand Up @@ -374,6 +377,7 @@ func TestRunListOrg(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
owner: "github",
Expand Down Expand Up @@ -428,6 +432,7 @@ func TestRunListEmpty(t *testing.T) {

ios, _, _, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{},
client: client,
Expand Down Expand Up @@ -504,6 +509,7 @@ func TestRunListWithClosed(t *testing.T) {

ios, _, stdout, _ := iostreams.Test()
config := listConfig{
//nolint:staticcheck // SA1019: tableprinter.NoHeaders temporarily allowed in project tests.
tp: tableprinter.New(ios, tableprinter.NoHeader),
opts: listOpts{
owner: "monalisa",
Expand Down
Loading
Loading