1package commands
2
3import (
4 "errors"
5 "fmt"
6
7 "github.com/MichaelMure/git-bug/cache"
8 "github.com/MichaelMure/git-bug/util/interrupt"
9 "github.com/spf13/cobra"
10)
11
12func runUser(cmd *cobra.Command, args []string) error {
13 backend, err := cache.NewRepoCache(repo)
14 if err != nil {
15 return err
16 }
17 defer backend.Close()
18 interrupt.RegisterCleaner(backend.Close)
19
20 if len(args) > 1 {
21 return errors.New("only one identity can be displayed at a time")
22 }
23
24 var id *cache.IdentityCache
25 if len(args) == 1 {
26 id, err = backend.ResolveIdentityPrefix(args[0])
27 } else {
28 id, err = backend.GetUserIdentity()
29 }
30
31 if err != nil {
32 return err
33 }
34
35 fmt.Printf("Id: %s\n", id.Id())
36 fmt.Printf("Name: %s\n", id.Name())
37 fmt.Printf("Login: %s\n", id.Login())
38 fmt.Printf("Email: %s\n", id.Email())
39 fmt.Printf("Last modification: %s (lamport %d)\n",
40 id.LastModification().Time().Format("Mon Jan 2 15:04:05 2006 +0200"),
41 id.LastModificationLamport())
42 // fmt.Printf("Protected: %v\n", id.IsProtected())
43
44 return nil
45}
46
47var userCmd = &cobra.Command{
48 Use: "user [<id>]",
49 Short: "Display or change the user identity.",
50 PreRunE: loadRepo,
51 RunE: runUser,
52}
53
54func init() {
55 RootCmd.AddCommand(userCmd)
56 userCmd.Flags().SortFlags = false
57}