aboutsummaryrefslogtreecommitdiffstats
path: root/commands/user_ls.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/user_ls.go')
-rw-r--r--commands/user_ls.go84
1 files changed, 23 insertions, 61 deletions
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]")
}