diff options
author | Michael Muré <batolettre@gmail.com> | 2019-03-01 23:17:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-01 23:17:57 +0100 |
commit | 7260ca05bc3588c0572887a7d8f1b897c7fc13da (patch) | |
tree | 66854358df3cb9de651f7688556ec5a4b8ab1868 /commands/user.go | |
parent | 0aefae6fcca5786f2c898029c3d6282f760f2c63 (diff) | |
parent | b6bed784e5664819250aac20b2b9690879ee6ab1 (diff) | |
download | git-bug-7260ca05bc3588c0572887a7d8f1b897c7fc13da.tar.gz |
Merge pull request #89 from MichaelMure/identity
WIP identity in git
Diffstat (limited to 'commands/user.go')
-rw-r--r-- | commands/user.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/commands/user.go b/commands/user.go new file mode 100644 index 00000000..12180321 --- /dev/null +++ b/commands/user.go @@ -0,0 +1,61 @@ +package commands + +import ( + "errors" + "fmt" + + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/util/interrupt" + "github.com/spf13/cobra" +) + +func runUser(cmd *cobra.Command, args []string) error { + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + interrupt.RegisterCleaner(backend.Close) + + if len(args) > 1 { + return errors.New("only one identity can be displayed at a time") + } + + var id *cache.IdentityCache + if len(args) == 1 { + id, err = backend.ResolveIdentityPrefix(args[0]) + } else { + id, err = backend.GetUserIdentity() + } + + if err != nil { + return err + } + + fmt.Printf("Id: %s\n", id.Id()) + fmt.Printf("Name: %s\n", id.Name()) + fmt.Printf("Login: %s\n", id.Login()) + fmt.Printf("Email: %s\n", id.Email()) + fmt.Printf("Last modification: %s (lamport %d)\n", + id.LastModification().Time().Format("Mon Jan 2 15:04:05 2006 +0200"), + id.LastModificationLamport()) + fmt.Println("Metadata:") + for key, value := range id.ImmutableMetadata() { + fmt.Printf(" %s --> %s\n", key, value) + } + // fmt.Printf("Protected: %v\n", id.IsProtected()) + + return nil +} + +var userCmd = &cobra.Command{ + Use: "user [<id>]", + Short: "Display or change the user identity.", + PreRunE: loadRepo, + RunE: runUser, +} + +func init() { + RootCmd.AddCommand(userCmd) + userCmd.Flags().SortFlags = false +} |