aboutsummaryrefslogtreecommitdiffstats
path: root/commands/ls.go
diff options
context:
space:
mode:
authorvince <vincetiu8@gmail.com>2020-06-23 17:51:42 +0800
committervince <vincetiu8@gmail.com>2020-06-23 17:51:42 +0800
commitfc3f6540b8fc941be76d01da49fcd43890ee7376 (patch)
tree4b8d1671dd490db91fac1fc9dde04f356c69d609 /commands/ls.go
parentcd8352edde7f4a26cb6b4dd922b05aa0bb23a70b (diff)
downloadgit-bug-fc3f6540b8fc941be76d01da49fcd43890ee7376.tar.gz
Add org-mode formatting option
This adds an option to the formatting flag on the ls, show and user ls commands that allows the user to specify the format of the output in org-mode. This will be useful for emacs users to read it in the editor.
Diffstat (limited to 'commands/ls.go')
-rw-r--r--commands/ls.go83
1 files changed, 81 insertions, 2 deletions
diff --git a/commands/ls.go b/commands/ls.go
index 41f48f91..99bdbe82 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -61,6 +61,8 @@ func runLsBug(_ *cobra.Command, args []string) error {
}
switch lsOutputFormat {
+ case "org-mode":
+ return lsOrgmodeFormatter(backend, bugExcerpt)
case "plain":
return lsPlainFormatter(backend, bugExcerpt)
case "json":
@@ -200,11 +202,88 @@ func lsDefaultFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerp
func lsPlainFormatter(_ *cache.RepoCache, bugExcerpts []*cache.BugExcerpt) error {
for _, b := range bugExcerpts {
- fmt.Printf("[%s] %s\n", b.Status, b.Title)
+ fmt.Printf("%s [%s] %s\n", b.Id.Human(), b.Status, b.Title)
}
return nil
}
+func lsOrgmodeFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerpt) error {
+ fmt.Println("+TODO: OPEN | CLOSED")
+
+ for _, b := range bugExcerpts {
+ status := strings.Title(b.Status.String())
+
+ var title string
+ if link, ok := b.CreateMetadata["github-url"]; ok {
+ title = fmt.Sprintf("[%s][%s]", link, b.Title)
+ } else {
+ title = b.Title
+ }
+
+ var name string
+ if b.AuthorId != "" {
+ author, err := backend.ResolveIdentityExcerpt(b.AuthorId)
+ if err != nil {
+ return err
+ }
+ name = author.DisplayName()
+ } else {
+ name = b.LegacyAuthor.DisplayName()
+ }
+
+ labels := b.Labels
+ labelsString := ":"
+ if len(labels) > 0 {
+ for _, label := range labels {
+ labelsString += label.String() + ":"
+ }
+ } else {
+ labelsString = ""
+ }
+
+ fmt.Printf("* %s %s [%s] %s: %s %s\n",
+ b.Id.Human(),
+ status,
+ time.Unix(b.CreateUnixTime, 0),
+ name,
+ title,
+ labelsString,
+ )
+
+ fmt.Printf("** Last Edited: %s\n",
+ time.Unix(b.EditUnixTime, 0).String(),
+ )
+
+ fmt.Printf("** Actors:\n")
+ for _, element := range b.Actors {
+ actor, err := backend.ResolveIdentityExcerpt(element)
+ if err != nil {
+ return err
+ }
+
+ fmt.Printf(": %s %s\n",
+ actor.Id.Human(),
+ actor.DisplayName(),
+ )
+ }
+
+ fmt.Printf("** Participants:\n")
+ for _, element := range b.Participants {
+ participant, err := backend.ResolveIdentityExcerpt(element)
+ if err != nil {
+ return err
+ }
+
+ fmt.Printf(": %s %s\n",
+ participant.Id.Human(),
+ participant.DisplayName(),
+ )
+ }
+ }
+
+ return nil
+}
+
// Finish the command flags transformation into the query.Query
func completeQuery() error {
for _, str := range lsStatusQuery {
@@ -287,5 +366,5 @@ func init() {
lsCmd.Flags().StringVarP(&lsSortDirection, "direction", "d", "asc",
"Select the sorting direction. Valid values are [asc,desc]")
lsCmd.Flags().StringVarP(&lsOutputFormat, "format", "f", "default",
- "Select the output formatting style. Valid values are [default,plain,json]")
+ "Select the output formatting style. Valid values are [default,plain,json,org-mode]")
}