aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--commands/ls.go56
-rw-r--r--commands/show.go146
-rw-r--r--commands/user_ls.go84
-rw-r--r--doc/man/git-bug-ls.12
-rw-r--r--doc/man/git-bug-show.18
-rw-r--r--doc/man/git-bug-user-ls.14
-rw-r--r--doc/md/git-bug_ls.md2
-rw-r--r--doc/md/git-bug_show.md5
-rw-r--r--doc/md/git-bug_user_ls.md3
-rw-r--r--misc/bash_completion/git-bug9
-rw-r--r--misc/powershell_completion/git-bug13
-rw-r--r--misc/zsh_completion/git-bug8
12 files changed, 104 insertions, 236 deletions
diff --git a/commands/ls.go b/commands/ls.go
index 7e3826fa..e1a7166a 100644
--- a/commands/ls.go
+++ b/commands/ls.go
@@ -95,18 +95,15 @@ func lsJsonFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerpt)
jsonBugs := make([]JSONBugExcerpt, len(bugExcerpts))
for i, b := range bugExcerpts {
jsonBug := JSONBugExcerpt{
- b.Id.String(),
- b.Id.Human(),
- time.Unix(b.CreateUnixTime, 0),
- time.Unix(b.EditUnixTime, 0),
- b.Status.String(),
- b.Labels,
- b.Title,
- []JSONIdentity{},
- []JSONIdentity{},
- JSONIdentity{},
- b.LenComments,
- b.CreateMetadata,
+ Id: b.Id.String(),
+ HumanId: b.Id.Human(),
+ CreationTime: time.Unix(b.CreateUnixTime, 0),
+ LastEdited: time.Unix(b.EditUnixTime, 0),
+ Status: b.Status.String(),
+ Labels: b.Labels,
+ Title: b.Title,
+ Comments: b.LenComments,
+ Metadata: b.CreateMetadata,
}
if b.AuthorId != "" {
@@ -114,46 +111,27 @@ func lsJsonFormatter(backend *cache.RepoCache, bugExcerpts []*cache.BugExcerpt)
if err != nil {
return err
}
-
- i, err := NewJSONIdentity(author)
- if err != nil {
- return err
- }
- jsonBug.Author = i
+ jsonBug.Author = NewJSONIdentityFromExcerpt(author)
} else {
- i, err := NewJSONIdentity(b.LegacyAuthor)
- if err != nil {
- return err
- }
- jsonBug.Author = i
+ jsonBug.Author = NewJSONIdentityFromLegacyExcerpt(&b.LegacyAuthor)
}
- for _, element := range b.Actors {
+ jsonBug.Actors = make([]JSONIdentity, len(b.Actors))
+ for i, element := range b.Actors {
actor, err := backend.ResolveIdentityExcerpt(element)
if err != nil {
return err
}
-
- i, err := NewJSONIdentity(actor)
- if err != nil {
- return err
- }
-
- jsonBug.Actors = append(jsonBug.Actors, i)
+ jsonBug.Actors[i] = NewJSONIdentityFromExcerpt(actor)
}
- for _, element := range b.Participants {
+ jsonBug.Participants = make([]JSONIdentity, len(b.Participants))
+ for i, element := range b.Participants {
participant, err := backend.ResolveIdentityExcerpt(element)
if err != nil {
return err
}
-
- i, err := NewJSONIdentity(participant)
- if err != nil {
- return err
- }
-
- jsonBug.Participants = append(jsonBug.Participants, i)
+ jsonBug.Participants[i] = NewJSONIdentityFromExcerpt(participant)
}
jsonBugs[i] = jsonBug
diff --git a/commands/show.go b/commands/show.go
index ae5a15ce..4915f181 100644
--- a/commands/show.go
+++ b/commands/show.go
@@ -4,14 +4,16 @@ import (
"encoding/json"
"errors"
"fmt"
+ "strings"
+ "time"
+
+ "github.com/spf13/cobra"
+
"github.com/MichaelMure/git-bug/bug"
"github.com/MichaelMure/git-bug/cache"
_select "github.com/MichaelMure/git-bug/commands/select"
"github.com/MichaelMure/git-bug/util/colors"
"github.com/MichaelMure/git-bug/util/interrupt"
- "github.com/spf13/cobra"
- "strings"
- "time"
)
var (
@@ -82,8 +84,6 @@ func runShowBug(_ *cobra.Command, args []string) error {
return showOrgmodeFormatter(snapshot)
case "json":
return showJsonFormatter(snapshot)
- case "plain":
- return showPlainFormatter(snapshot)
case "default":
return showDefaultFormatter(snapshot)
default:
@@ -165,83 +165,6 @@ func showDefaultFormatter(snapshot *bug.Snapshot) error {
return nil
}
-func showPlainFormatter(snapshot *bug.Snapshot) error {
- // Header
- fmt.Printf("%s [%s] %s\n",
- snapshot.Id().Human(),
- snapshot.Status,
- snapshot.Title,
- )
-
- fmt.Printf("author: %s\n",
- snapshot.Author.DisplayName(),
- )
-
- fmt.Printf("creation time: %s\n",
- snapshot.CreatedAt.String(),
- )
-
- fmt.Printf("last edit: %s\n",
- snapshot.LastEditTime().String(),
- )
-
- // Labels
- var labels = make([]string, len(snapshot.Labels))
- for i := range snapshot.Labels {
- labels[i] = string(snapshot.Labels[i])
- }
-
- fmt.Printf("labels: %s\n",
- strings.Join(labels, ", "),
- )
-
- // Actors
- var actors = make([]string, len(snapshot.Actors))
- for i := range snapshot.Actors {
- actors[i] = snapshot.Actors[i].DisplayName()
- }
-
- fmt.Printf("actors: %s\n",
- strings.Join(actors, ", "),
- )
-
- // Participants
- var participants = make([]string, len(snapshot.Participants))
- for i := range snapshot.Participants {
- participants[i] = snapshot.Participants[i].DisplayName()
- }
-
- fmt.Printf("participants: %s\n",
- strings.Join(participants, ", "),
- )
-
- // Comments
- indent := " "
-
- for i, comment := range snapshot.Comments {
- var message string
- fmt.Printf("%s#%d %s <%s>\n",
- indent,
- i,
- comment.Author.DisplayName(),
- comment.Author.Email(),
- )
-
- if comment.Message == "" {
- message = "No description provided."
- } else {
- message = comment.Message
- }
-
- fmt.Printf("%s%s\n",
- indent,
- strings.ReplaceAll(message, "\n", fmt.Sprintf("\n%s", indent)),
- )
- }
-
- return nil
-}
-
type JSONBugSnapshot struct {
Id string `json:"id"`
HumanId string `json:"human_id"`
@@ -259,47 +182,31 @@ type JSONBugSnapshot struct {
}
type JSONComment struct {
- Id int `json:"id"`
- AuthorName string `json:"author_name"`
- AuthorLogin string `json:"author_login"`
- Message string `json:"message"`
+ Id int `json:"id"`
+ Author JSONIdentity `json:"author"`
+ Message string `json:"message"`
}
func showJsonFormatter(snapshot *bug.Snapshot) error {
jsonBug := JSONBugSnapshot{
- snapshot.Id().String(),
- snapshot.Id().Human(),
- snapshot.CreatedAt,
- snapshot.LastEditTime(),
- snapshot.Status.String(),
- snapshot.Labels,
- snapshot.Title,
- JSONIdentity{},
- []JSONIdentity{},
- []JSONIdentity{},
- []JSONComment{},
- }
-
- author, err := NewJSONIdentity(snapshot.Author)
- if err != nil {
- return err
+ Id: snapshot.Id().String(),
+ HumanId: snapshot.Id().Human(),
+ CreationTime: snapshot.CreatedAt,
+ LastEdited: snapshot.LastEditTime(),
+ Status: snapshot.Status.String(),
+ Labels: snapshot.Labels,
+ Title: snapshot.Title,
+ Author: NewJSONIdentity(snapshot.Author),
}
- jsonBug.Author = author
- for _, element := range snapshot.Actors {
- actor, err := NewJSONIdentity(element)
- if err != nil {
- return err
- }
- jsonBug.Actors = append(jsonBug.Actors, actor)
+ jsonBug.Actors = make([]JSONIdentity, len(snapshot.Actors))
+ for i, element := range snapshot.Actors {
+ jsonBug.Actors[i] = NewJSONIdentity(element)
}
- for _, element := range snapshot.Participants {
- participant, err := NewJSONIdentity(element)
- if err != nil {
- return err
- }
- jsonBug.Participants = append(jsonBug.Participants, participant)
+ jsonBug.Participants = make([]JSONIdentity, len(snapshot.Participants))
+ for i, element := range snapshot.Participants {
+ jsonBug.Participants[i] = NewJSONIdentity(element)
}
for i, comment := range snapshot.Comments {
@@ -310,10 +217,9 @@ func showJsonFormatter(snapshot *bug.Snapshot) error {
message = comment.Message
}
jsonBug.Comments = append(jsonBug.Comments, JSONComment{
- i,
- comment.Author.Name(),
- comment.Author.Login(),
- message,
+ Id: i,
+ Author: NewJSONIdentity(comment.Author),
+ Message: message,
})
}
@@ -417,5 +323,5 @@ func init() {
showCmd.Flags().StringVarP(&showFieldsQuery, "field", "", "",
"Select field to display. Valid values are [author,authorEmail,createTime,lastEdit,humanId,id,labels,shortId,status,title,actors,participants]")
showCmd.Flags().StringVarP(&showOutputFormat, "format", "f", "default",
- "Select the output formatting style. Valid values are [default,plain,json,org-mode]")
+ "Select the output formatting style. Valid values are [default,json,org-mode]")
}
diff --git a/commands/user_ls.go b/commands/user_ls.go
index b0ebfdd5..78ef8258 100644
--- a/commands/user_ls.go
+++ b/commands/user_ls.go
@@ -2,14 +2,12 @@ package commands
import (
"encoding/json"
- "errors"
"fmt"
- "reflect"
"github.com/spf13/cobra"
"github.com/MichaelMure/git-bug/cache"
- identity2 "github.com/MichaelMure/git-bug/identity"
+ "github.com/MichaelMure/git-bug/identity"
"github.com/MichaelMure/git-bug/util/colors"
"github.com/MichaelMure/git-bug/util/interrupt"
)
@@ -37,12 +35,8 @@ func runUserLs(_ *cobra.Command, _ []string) error {
}
switch userLsOutputFormat {
- case "org-mode":
- return userLsOrgmodeFormatter(users)
case "json":
return userLsJsonFormatter(users)
- case "plain":
- return userLsPlainFormatter(users)
case "default":
return userLsDefaultFormatter(users)
default:
@@ -57,46 +51,29 @@ type JSONIdentity struct {
Login string `json:"login"`
}
-func NewJSONIdentity(id interface{}) (JSONIdentity, error) {
- switch id.(type) {
- case *cache.IdentityExcerpt:
- i := id.(*cache.IdentityExcerpt)
- return JSONIdentity{
- i.Id.String(),
- i.Id.Human(),
- i.Name,
- i.Login,
- }, nil
- case identity2.Interface:
- i := id.(identity2.Interface)
- return JSONIdentity{
- i.Id().String(),
- i.Id().Human(),
- i.Name(),
- i.Login(),
- }, nil
- case cache.LegacyAuthorExcerpt:
- i := id.(cache.LegacyAuthorExcerpt)
- return JSONIdentity{
- "",
- "",
- i.Name,
- i.Login,
- }, nil
- default:
- return JSONIdentity{}, errors.New(fmt.Sprintf("Inconvertible type, attempting to convert type %s to type %s.", reflect.TypeOf(id).String(), reflect.TypeOf(JSONIdentity{}).String()))
+func NewJSONIdentity(i identity.Interface) JSONIdentity {
+ return JSONIdentity{
+ Id: i.Id().String(),
+ HumanId: i.Id().Human(),
+ Name: i.Name(),
+ Login: i.Login(),
}
}
-func userLsPlainFormatter(users []*cache.IdentityExcerpt) error {
- for _, user := range users {
- fmt.Printf("%s %s\n",
- user.Id.Human(),
- user.DisplayName(),
- )
+func NewJSONIdentityFromExcerpt(excerpt *cache.IdentityExcerpt) JSONIdentity {
+ return JSONIdentity{
+ Id: excerpt.Id.String(),
+ HumanId: excerpt.Id.Human(),
+ Name: excerpt.Name,
+ Login: excerpt.Login,
}
+}
- return nil
+func NewJSONIdentityFromLegacyExcerpt(excerpt *cache.LegacyAuthorExcerpt) JSONIdentity {
+ return JSONIdentity{
+ Name: excerpt.Name,
+ Login: excerpt.Login,
+ }
}
func userLsDefaultFormatter(users []*cache.IdentityExcerpt) error {
@@ -111,13 +88,9 @@ func userLsDefaultFormatter(users []*cache.IdentityExcerpt) error {
}
func userLsJsonFormatter(users []*cache.IdentityExcerpt) error {
- jsonUsers := []JSONIdentity{}
- for _, user := range users {
- jsonUser, err := NewJSONIdentity(user)
- if err != nil {
- return err
- }
- jsonUsers = append(jsonUsers, jsonUser)
+ jsonUsers := make([]JSONIdentity, len(users))
+ for i, user := range users {
+ jsonUsers[i] = NewJSONIdentityFromExcerpt(user)
}
jsonObject, _ := json.MarshalIndent(jsonUsers, "", " ")
@@ -125,17 +98,6 @@ func userLsJsonFormatter(users []*cache.IdentityExcerpt) error {
return nil
}
-func userLsOrgmodeFormatter(users []*cache.IdentityExcerpt) error {
- for _, user := range users {
- fmt.Printf("* %s %s\n",
- user.Id.Human(),
- user.DisplayName(),
- )
- }
-
- return nil
-}
-
var userLsCmd = &cobra.Command{
Use: "ls",
Short: "List identities.",
@@ -147,5 +109,5 @@ func init() {
userCmd.AddCommand(userLsCmd)
userLsCmd.Flags().SortFlags = false
userLsCmd.Flags().StringVarP(&userLsOutputFormat, "format", "f", "default",
- "Select the output formatting style. Valid values are [default,plain,json,org-mode]")
+ "Select the output formatting style. Valid values are [default,json]")
}
diff --git a/doc/man/git-bug-ls.1 b/doc/man/git-bug-ls.1
index 5d05cfcd..54a64cd2 100644
--- a/doc/man/git-bug-ls.1
+++ b/doc/man/git-bug-ls.1
@@ -59,7 +59,7 @@ You can pass an additional query to filter and order the list. This query can be
.PP
\fB\-f\fP, \fB\-\-format\fP="default"
- Select the output formatting style. Valid values are [default, plain(text), json]
+ Select the output formatting style. Valid values are [default,plain,json,org\-mode]
.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
diff --git a/doc/man/git-bug-show.1 b/doc/man/git-bug-show.1
index dae1877b..eb694dac 100644
--- a/doc/man/git-bug-show.1
+++ b/doc/man/git-bug-show.1
@@ -19,8 +19,12 @@ Display the details of a bug.
.SH OPTIONS
.PP
-\fB\-f\fP, \fB\-\-field\fP=""
- Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]
+\fB\-\-field\fP=""
+ Select field to display. Valid values are [author,authorEmail,createTime,lastEdit,humanId,id,labels,shortId,status,title,actors,participants]
+
+.PP
+\fB\-f\fP, \fB\-\-format\fP="default"
+ Select the output formatting style. Valid values are [default,json,org\-mode]
.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
diff --git a/doc/man/git-bug-user-ls.1 b/doc/man/git-bug-user-ls.1
index 1ccddb8a..14bc9ff7 100644
--- a/doc/man/git-bug-user-ls.1
+++ b/doc/man/git-bug-user-ls.1
@@ -19,6 +19,10 @@ List identities.
.SH OPTIONS
.PP
+\fB\-f\fP, \fB\-\-format\fP="default"
+ Select the output formatting style. Valid values are [default,json]
+
+.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for ls
diff --git a/doc/md/git-bug_ls.md b/doc/md/git-bug_ls.md
index 32941e4f..1532efab 100644
--- a/doc/md/git-bug_ls.md
+++ b/doc/md/git-bug_ls.md
@@ -35,7 +35,7 @@ git bug ls --status closed --by creation
-n, --no strings Filter by absence of something. Valid values are [label]
-b, --by string Sort the results by a characteristic. Valid values are [id,creation,edit] (default "creation")
-d, --direction string Select the sorting direction. Valid values are [asc,desc] (default "asc")
- -f, --format string Select the output formatting style. Valid values are [default, plain(text), json] (default "default")
+ -f, --format string Select the output formatting style. Valid values are [default,plain,json,org-mode] (default "default")
-h, --help help for ls
```
diff --git a/doc/md/git-bug_show.md b/doc/md/git-bug_show.md
index 40152ede..e6d2d7ba 100644
--- a/doc/md/git-bug_show.md
+++ b/doc/md/git-bug_show.md
@@ -13,8 +13,9 @@ git-bug show [<id>] [flags]
### Options
```
- -f, --field string Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]
- -h, --help help for show
+ --field string Select field to display. Valid values are [author,authorEmail,createTime,lastEdit,humanId,id,labels,shortId,status,title,actors,participants]
+ -f, --format string Select the output formatting style. Valid values are [default,json,org-mode] (default "default")
+ -h, --help help for show
```
### SEE ALSO
diff --git a/doc/md/git-bug_user_ls.md b/doc/md/git-bug_user_ls.md
index d390ed2a..51f01712 100644
--- a/doc/md/git-bug_user_ls.md
+++ b/doc/md/git-bug_user_ls.md
@@ -13,7 +13,8 @@ git-bug user ls [flags]
### Options
```
- -h, --help help for ls
+ -f, --format string Select the output formatting style. Valid values are [default,json] (default "default")
+ -h, --help help for ls
```
### SEE ALSO
diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug
index 93c75b8e..c3e62849 100644
--- a/misc/bash_completion/git-bug
+++ b/misc/bash_completion/git-bug
@@ -933,8 +933,11 @@ _git-bug_show()
flags+=("--field=")
two_word_flags+=("--field")
- two_word_flags+=("-f")
local_nonpersistent_flags+=("--field=")
+ flags+=("--format=")
+ two_word_flags+=("--format")
+ two_word_flags+=("-f")
+ local_nonpersistent_flags+=("--format=")
must_have_one_flag=()
must_have_one_noun=()
@@ -1122,6 +1125,10 @@ _git-bug_user_ls()
flags_with_completion=()
flags_completion=()
+ flags+=("--format=")
+ two_word_flags+=("--format")
+ two_word_flags+=("-f")
+ local_nonpersistent_flags+=("--format=")
must_have_one_flag=()
must_have_one_noun=()
diff --git a/misc/powershell_completion/git-bug b/misc/powershell_completion/git-bug
index 9f51c785..0a8c7b5a 100644
--- a/misc/powershell_completion/git-bug
+++ b/misc/powershell_completion/git-bug
@@ -159,8 +159,8 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock {
[CompletionResult]::new('--by', 'by', [CompletionResultType]::ParameterName, 'Sort the results by a characteristic. Valid values are [id,creation,edit]')
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'Select the sorting direction. Valid values are [asc,desc]')
[CompletionResult]::new('--direction', 'direction', [CompletionResultType]::ParameterName, 'Select the sorting direction. Valid values are [asc,desc]')
- [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default, plain(text), json]')
- [CompletionResult]::new('--format', 'format', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default, plain(text), json]')
+ [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default,plain,json,org-mode]')
+ [CompletionResult]::new('--format', 'format', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default,plain,json,org-mode]')
break
}
'git-bug;ls-id' {
@@ -179,8 +179,9 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock {
break
}
'git-bug;show' {
- [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]')
- [CompletionResult]::new('--field', 'field', [CompletionResultType]::ParameterName, 'Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]')
+ [CompletionResult]::new('--field', 'field', [CompletionResultType]::ParameterName, 'Select field to display. Valid values are [author,authorEmail,createTime,lastEdit,humanId,id,labels,shortId,status,title,actors,participants]')
+ [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default,json,org-mode]')
+ [CompletionResult]::new('--format', 'format', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default,json,org-mode]')
break
}
'git-bug;status' {
@@ -221,6 +222,8 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock {
break
}
'git-bug;user;ls' {
+ [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default,json]')
+ [CompletionResult]::new('--format', 'format', [CompletionResultType]::ParameterName, 'Select the output formatting style. Valid values are [default,json]')
break
}
'git-bug;version' {
@@ -242,4 +245,4 @@ Register-ArgumentCompleter -Native -CommandName 'git-bug' -ScriptBlock {
})
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
-}
+} \ No newline at end of file
diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug
index 18a49668..ba15f3bc 100644
--- a/misc/zsh_completion/git-bug
+++ b/misc/zsh_completion/git-bug
@@ -304,7 +304,7 @@ function _git-bug_ls {
'(*-n *--no)'{\*-n,\*--no}'[Filter by absence of something. Valid values are [label]]:' \
'(-b --by)'{-b,--by}'[Sort the results by a characteristic. Valid values are [id,creation,edit]]:' \
'(-d --direction)'{-d,--direction}'[Select the sorting direction. Valid values are [asc,desc]]:' \
- '(-f --format)'{-f,--format}'[Select the output formatting style. Valid values are [default, plain(text), json]]:'
+ '(-f --format)'{-f,--format}'[Select the output formatting style. Valid values are [default,plain,json,org-mode]]:'
}
function _git-bug_ls-id {
@@ -329,7 +329,8 @@ function _git-bug_select {
function _git-bug_show {
_arguments \
- '(-f --field)'{-f,--field}'[Select field to display. Valid values are [author,authorEmail,createTime,humanId,id,labels,shortId,status,title,actors,participants]]:'
+ '--field[Select field to display. Valid values are [author,authorEmail,createTime,lastEdit,humanId,id,labels,shortId,status,title,actors,participants]]:' \
+ '(-f --format)'{-f,--format}'[Select the output formatting style. Valid values are [default,json,org-mode]]:'
}
@@ -443,7 +444,8 @@ function _git-bug_user_create {
}
function _git-bug_user_ls {
- _arguments
+ _arguments \
+ '(-f --format)'{-f,--format}'[Select the output formatting style. Valid values are [default,json]]:'
}
function _git-bug_version {