Skip to content

Commit 269adab

Browse files
committed
improve list output
1 parent 02d94d6 commit 269adab

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

pkg/cmd/gist/list/http.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,13 @@ import (
55
"net/http"
66
"net/url"
77
"sort"
8-
"time"
98

109
"github.com/cli/cli/api"
10+
"github.com/cli/cli/pkg/cmd/gist/shared"
1111
)
1212

13-
type Gist struct {
14-
Description string
15-
HTMLURL string `json:"html_url"`
16-
UpdatedAt time.Time `json:"updated_at"`
17-
Public bool
18-
}
19-
20-
func listGists(client *http.Client, hostname string, limit int, visibility string) ([]Gist, error) {
21-
result := []Gist{}
13+
func listGists(client *http.Client, hostname string, limit int, visibility string) ([]shared.Gist, error) {
14+
result := []shared.Gist{}
2215

2316
query := url.Values{}
2417
if visibility == "all" {
@@ -33,7 +26,7 @@ func listGists(client *http.Client, hostname string, limit int, visibility strin
3326
return nil, err
3427
}
3528

36-
gists := []Gist{}
29+
gists := []shared.Gist{}
3730

3831
for _, gist := range result {
3932
if len(gists) == limit {

pkg/cmd/gist/list/list.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package list
33
import (
44
"fmt"
55
"net/http"
6+
"time"
67

78
"github.com/cli/cli/internal/ghinstance"
89
"github.com/cli/cli/pkg/cmdutil"
@@ -75,14 +76,24 @@ func listRun(opts *ListOptions) error {
7576
tp := utils.NewTablePrinter(opts.IO)
7677

7778
for _, gist := range gists {
78-
// TODO i was getting confusing results with table printer's truncation
79-
description := gist.Description
80-
if len(description) > 30 {
81-
description = description[0:27] + "..."
79+
fileCount := 0
80+
for _, _ = range gist.Files {
81+
fileCount++
8282
}
8383

84-
tp.AddField(description, nil, cs.Bold)
85-
tp.AddField(gist.HTMLURL, nil, nil)
84+
visibility := "public"
85+
visColor := cs.Green
86+
if !gist.Public {
87+
visibility = "secret"
88+
visColor = cs.Red
89+
}
90+
91+
updatedAt := utils.FuzzyAgo(time.Since(gist.UpdatedAt))
92+
tp.AddField(gist.ID, nil, nil)
93+
tp.AddField(gist.Description, nil, cs.Bold)
94+
tp.AddField(utils.Pluralize(fileCount, "file"), nil, nil)
95+
tp.AddField(visibility, nil, visColor)
96+
tp.AddField(updatedAt, nil, utils.Gray)
8697
tp.EndRow()
8798
}
8899

pkg/cmd/gist/shared/shared.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package shared
33
import (
44
"fmt"
55
"net/http"
6+
"time"
67

78
"github.com/cli/cli/api"
89
)
@@ -20,6 +21,8 @@ type Gist struct {
2021
ID string `json:"id,omitempty"`
2122
Description string `json:"description"`
2223
Files map[string]*GistFile `json:"files"`
24+
UpdatedAt time.Time `json:"updated_at"`
25+
Public bool
2326
}
2427

2528
func GetGist(client *http.Client, hostname, gistID string) (*Gist, error) {

0 commit comments

Comments
 (0)