Skip to content

Commit

Permalink
show filename if no description
Browse files Browse the repository at this point in the history
  • Loading branch information
vilmibm committed Sep 15, 2020
1 parent ba5b639 commit a61c897
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
13 changes: 12 additions & 1 deletion pkg/cmd/gist/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package list
import (
"fmt"
"net/http"
"strings"
"time"

"github.com/cli/cli/internal/ghinstance"
Expand Down Expand Up @@ -93,8 +94,18 @@ func listRun(opts *ListOptions) error {
visColor = cs.Red
}

description := gist.Description
if description == "" {
for filename, _ := range gist.Files {
if !strings.HasPrefix(filename, "gistfile") {
description = filename
break
}
}
}

tp.AddField(gist.ID, nil, nil)
tp.AddField(gist.Description, nil, cs.Bold)
tp.AddField(description, nil, cs.Bold)
tp.AddField(utils.Pluralize(fileCount, "file"), nil, nil)
tp.AddField(visibility, nil, visColor)
if tp.IsTTY() {
Expand Down
28 changes: 15 additions & 13 deletions pkg/cmd/gist/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ func Test_listRun(t *testing.T) {
{
name: "default behavior",
opts: &ListOptions{},
wantOut: "1234567890 1 file public about 6 hours ago\n2345678901 tea leaves thwart... 2 files secret about 6 hours ago\n3456789012 short desc 11 files secret about 6 hours ago\n",
wantOut: "1234567890 cool.txt 1 file public about 6 hours ago\n4567890123 1 file public about 6 hours ago\n2345678901 tea leaves thwart... 2 files secret about 6 hours ago\n3456789012 short desc 11 files secret about 6 hours ago\n",
},
{
name: "with public filter",
opts: &ListOptions{Visibility: "public"},
wantOut: "1234567890 1 file public about 6 hours ago\n",
wantOut: "1234567890 cool.txt 1 file public about 6 hours ago\n4567890123 1 file public about 6 hours ago\n",
},
{
name: "with secret filter",
Expand All @@ -123,12 +123,12 @@ func Test_listRun(t *testing.T) {
{
name: "with limit",
opts: &ListOptions{Limit: 1},
wantOut: "1234567890 1 file public about 6 hours ago\n",
wantOut: "1234567890 cool.txt 1 file public about 6 hours ago\n",
},
{
name: "nontty output",
opts: &ListOptions{},
wantOut: "1234567890\t\t1 file\tpublic\t0001-01-01 00:00:00 +0000 UTC\n2345678901\ttea leaves thwart those who court catastrophe\t2 files\tsecret\t0001-01-01 00:00:00 +0000 UTC\n3456789012\tshort desc\t11 files\tsecret\t0001-01-01 00:00:00 +0000 UTC\n",
wantOut: "1234567890\tcool.txt\t1 file\tpublic\t0001-01-01 00:00:00 +0000 UTC\n4567890123\t\t1 file\tpublic\t0001-01-01 00:00:00 +0000 UTC\n2345678901\ttea leaves thwart those who court catastrophe\t2 files\tsecret\t0001-01-01 00:00:00 +0000 UTC\n3456789012\tshort desc\t11 files\tsecret\t0001-01-01 00:00:00 +0000 UTC\n",
nontty: true,
},
}
Expand All @@ -142,22 +142,24 @@ func Test_listRun(t *testing.T) {
ID: "1234567890",
Description: "",
Files: map[string]*shared.GistFile{
"cool.txt": {
Content: "lol",
},
"cool.txt": {},
},
Public: true,
},
{
ID: "4567890123",
Description: "",
Files: map[string]*shared.GistFile{
"gistfile0.txt": {},
},
Public: true,
},
{
ID: "2345678901",
Description: "tea leaves thwart those who court catastrophe",
Files: map[string]*shared.GistFile{
"gistfile0.txt": {
Content: "lolol",
},
"gistfile1.txt": {
Content: "lololol",
},
"gistfile0.txt": {},
"gistfile1.txt": {},
},
Public: false,
},
Expand Down

0 comments on commit a61c897

Please sign in to comment.