aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-07-14 19:16:27 +0200
committerGitHub <noreply@github.com>2020-07-14 19:16:27 +0200
commit47b12555611d515f922c2017e77d1dac80df5bd3 (patch)
tree8efb24c5c199950c7c082e60cd5f6a750b0d8179
parentf3304bdc1c215e733b9a2ee6a228e64f663c2b09 (diff)
parent5c823a702496c57a9adb307dddb22c5c59486548 (diff)
downloadgit-bug-47b12555611d515f922c2017e77d1dac80df5bd3.tar.gz
Merge pull request #425 from karlicoss/ls-org-mode
ls --format org-mode enhancements
-rw-r--r--commands/ls.go43
1 files changed, 27 insertions, 16 deletions
diff --git a/commands/ls.go b/commands/ls.go
index ad61a852..950e2aa0 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -3,6 +3,7 @@ package commands
import (
"encoding/json"
"fmt"
+ "regexp"
"strings"
"time"
@@ -76,8 +77,6 @@ git bug ls --status closed --by creation
}
func runLs(env *Env, opts lsOptions, args []string) error {
- time.Sleep(5 * time.Second)
-
var q *query.Query
var err error
@@ -237,14 +236,24 @@ func lsPlainFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error {
}
func lsOrgmodeFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error {
- env.out.Println("+TODO: OPEN | CLOSED")
+ // see https://orgmode.org/manual/Tags.html
+ orgTagRe := regexp.MustCompile("[^[:alpha:]_@]")
+ formatTag := func(l bug.Label) string {
+ return orgTagRe.ReplaceAllString(l.String(), "_")
+ }
+
+ formatTime := func(time time.Time) string {
+ return time.Format("[2006-01-02 Mon 15:05]")
+ }
+
+ env.out.Println("#+TODO: OPEN | CLOSED")
for _, b := range bugExcerpts {
- status := strings.Title(b.Status.String())
+ status := strings.ToUpper(b.Status.String())
var title string
if link, ok := b.CreateMetadata["github-url"]; ok {
- title = fmt.Sprintf("[%s][%s]", link, b.Title)
+ title = fmt.Sprintf("[[%s][%s]]", link, b.Title)
} else {
title = b.Title
}
@@ -260,24 +269,26 @@ func lsOrgmodeFormatter(env *Env, bugExcerpts []*cache.BugExcerpt) error {
name = b.LegacyAuthor.DisplayName()
}
- labels := b.Labels
- var labelsString string
- if len(labels) > 0 {
- labelsString = fmt.Sprintf(":%s:", strings.Replace(fmt.Sprint(labels), " ", ":", -1))
- } else {
- labelsString = ""
+ var labels strings.Builder
+ labels.WriteString(":")
+ for i, l := range b.Labels {
+ if i > 0 {
+ labels.WriteString(":")
+ }
+ labels.WriteString(formatTag(l))
}
+ labels.WriteString(":")
- env.out.Printf("* %s %s [%s] %s: %s %s\n",
- b.Id.Human(),
+ env.out.Printf("* %-6s %s %s %s: %s %s\n",
status,
- b.CreateTime(),
+ b.Id.Human(),
+ formatTime(b.CreateTime()),
name,
title,
- labelsString,
+ labels.String(),
)
- env.out.Printf("** Last Edited: %s\n", b.EditTime().String())
+ env.out.Printf("** Last Edited: %s\n", formatTime(b.EditTime()))
env.out.Printf("** Actors:\n")
for _, element := range b.Actors {