Add tea issues --fields, allow printing labels #312

Merged
6543 merged 16 commits from noerw/tea:print-issue-fields-labels into master 2020-12-21 15:41:07 +00:00
3 changed files with 29 additions and 14 deletions
Showing only changes of commit 9ad989cdd5 - Show all commits

View File

@ -21,17 +21,26 @@ func LabelsList(labels []*gitea.Label, output string) {
"Description",
)
p := termenv.ColorProfile()
for _, label := range labels {
color := termenv.String(label.Color)
t.addRow(
strconv.FormatInt(label.ID, 10),
fmt.Sprint(color.Background(p.Color("#"+label.Color))),
formatLabel(label, !isMachineReadable(output), label.Color),
label.Name,
label.Description,
)
}
t.print(output)
}
func formatLabel(label *gitea.Label, allowColor bool, text string) string {
colorProfile := termenv.Ascii
if allowColor {
colorProfile = termenv.EnvColorProfile()
}
if len(text) == 0 {
text = label.Name
}
styled := termenv.String(text)
styled = styled.Foreground(colorProfile.Color("#" + label.Color))
return fmt.Sprint(styled)
}

View File

@ -72,16 +72,16 @@ func (t table) Less(i, j int) bool {
}
func (t *table) print(output string) {
switch {
case output == "" || output == "table":
switch output {
case "", "table":
outputtable(t.headers, t.values)
case output == "csv":
case "csv":
outputdsv(t.headers, t.values, ",")
case output == "simple":
case "simple":
outputsimple(t.headers, t.values)
case output == "tsv":
case "tsv":
outputdsv(t.headers, t.values, "\t")
case output == "yaml":
case "yml", "yaml":
outputyaml(t.headers, t.values)
default:
fmt.Printf("unknown output type '" + output + "', available types are:\n- csv: comma-separated values\n- simple: space-separated values\n- table: auto-aligned table format (default)\n- tsv: tab-separated values\n- yaml: YAML format\n")
@ -137,3 +137,11 @@ func outputyaml(headers []string, values [][]string) {
}
}
}
func isMachineReadable(outputFormat string) bool {
switch outputFormat {
case "yml", "yaml", "csv":
return true
}
return false
}

View File

@ -13,9 +13,7 @@ import (
)
func formatDuration(seconds int64, outputType string) string {
switch outputType {
case "yaml":
case "csv":
if isMachineReadable(outputType) {
return fmt.Sprint(seconds)
}
return time.Duration(1e9 * seconds).String()