aboutsummaryrefslogtreecommitdiffstats
path: root/commands/user_list.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-02-24 14:17:52 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:48:51 +0100
commit7a80d8f849861a6033cd0765e5d85a52b08a8854 (patch)
tree30a2b00bec3e871aa18ba75acac626f9e7e1f1b2 /commands/user_list.go
parent8bba6d1493fdf064ac9fede0a5098b1abe969052 (diff)
downloadgit-bug-7a80d8f849861a6033cd0765e5d85a52b08a8854.tar.gz
commands: add a super-fast "user ls" command
Diffstat (limited to 'commands/user_list.go')
-rw-r--r--commands/user_list.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/commands/user_list.go b/commands/user_list.go
new file mode 100644
index 00000000..4d6e5e12
--- /dev/null
+++ b/commands/user_list.go
@@ -0,0 +1,47 @@
+package commands
+
+import (
+ "fmt"
+
+ "github.com/MichaelMure/git-bug/cache"
+ "github.com/MichaelMure/git-bug/util/colors"
+ "github.com/MichaelMure/git-bug/util/interrupt"
+ "github.com/spf13/cobra"
+)
+
+var (
+ userLsVerbose bool
+)
+
+func runUserLs(cmd *cobra.Command, args []string) error {
+ backend, err := cache.NewRepoCache(repo)
+ if err != nil {
+ return err
+ }
+ defer backend.Close()
+ interrupt.RegisterCleaner(backend.Close)
+
+ for _, i := range backend.AllIdentityExcerpt() {
+ fmt.Printf("%s %s\n",
+ colors.Cyan(i.HumanId()),
+ i.DisplayName(),
+ )
+ }
+
+ return nil
+}
+
+var userLsCmd = &cobra.Command{
+ Use: "ls",
+ Short: "List identities",
+ PreRunE: loadRepo,
+ RunE: runUserLs,
+}
+
+func init() {
+ userCmd.AddCommand(userLsCmd)
+ userLsCmd.Flags().SortFlags = false
+
+ userLsCmd.Flags().BoolVarP(&userLsVerbose, "verbose", "v", false,
+ "Print extra information")
+}