|
1 | 1 | package list |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "fmt" |
4 | 5 | "net/http" |
5 | 6 | "time" |
6 | 7 |
|
@@ -64,10 +65,45 @@ func listRun(opts *ListOptions) error { |
64 | 65 |
|
65 | 66 | now := time.Now() |
66 | 67 | table := utils.NewTablePrinter(opts.IO) |
| 68 | + iofmt := opts.IO.ColorScheme() |
| 69 | + seenLatest := false |
67 | 70 | for _, rel := range releases { |
68 | | - table.AddField(rel.TagName, nil, nil) |
69 | | - table.AddField(text.ReplaceExcessiveWhitespace(rel.Name), nil, nil) |
70 | | - table.AddField(utils.FuzzyAgo(now.Sub(rel.PublishedAt)), nil, nil) |
| 71 | + title := text.ReplaceExcessiveWhitespace(rel.Name) |
| 72 | + if title == "" { |
| 73 | + title = rel.TagName |
| 74 | + } |
| 75 | + table.AddField(title, nil, nil) |
| 76 | + |
| 77 | + badge := "" |
| 78 | + var badgeColor func(string) string |
| 79 | + if !rel.IsDraft && !rel.IsPrerelease && !seenLatest { |
| 80 | + badge = "Latest" |
| 81 | + badgeColor = iofmt.Green |
| 82 | + seenLatest = true |
| 83 | + } else if rel.IsDraft { |
| 84 | + badge = "Draft" |
| 85 | + badgeColor = iofmt.Red |
| 86 | + } else if rel.IsPrerelease { |
| 87 | + badge = "Pre-release" |
| 88 | + badgeColor = iofmt.Yellow |
| 89 | + } |
| 90 | + table.AddField(badge, nil, badgeColor) |
| 91 | + |
| 92 | + tagName := rel.TagName |
| 93 | + if table.IsTTY() { |
| 94 | + tagName = fmt.Sprintf("(%s)", tagName) |
| 95 | + } |
| 96 | + table.AddField(tagName, nil, nil) |
| 97 | + |
| 98 | + pubDate := rel.PublishedAt |
| 99 | + if rel.PublishedAt.IsZero() { |
| 100 | + pubDate = rel.CreatedAt |
| 101 | + } |
| 102 | + publishedAt := pubDate.String() |
| 103 | + if table.IsTTY() { |
| 104 | + publishedAt = utils.FuzzyAgo(now.Sub(pubDate)) |
| 105 | + } |
| 106 | + table.AddField(publishedAt, nil, iofmt.Gray) |
71 | 107 | table.EndRow() |
72 | 108 | } |
73 | 109 | err = table.Render() |
|
0 commit comments