2019-02-17 18:12:06 +03:00
|
|
|
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())
|
2019-02-25 01:05:03 +03:00
|
|
|
fmt.Printf("Last modification: %s (lamport %d)\n",
|
|
|
|
id.LastModification().Time().Format("Mon Jan 2 15:04:05 2006 +0200"),
|
|
|
|
id.LastModificationLamport())
|
2019-02-27 00:27:30 +03:00
|
|
|
fmt.Println("Metadata:")
|
|
|
|
for key, value := range id.ImmutableMetadata() {
|
|
|
|
fmt.Printf(" %s --> %s\n", key, value)
|
|
|
|
}
|
2019-02-19 01:16:47 +03:00
|
|
|
// fmt.Printf("Protected: %v\n", id.IsProtected())
|
2019-02-17 18:12:06 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var userCmd = &cobra.Command{
|
2019-03-23 21:03:39 +03:00
|
|
|
Use: "user [<user-id>]",
|
2019-02-24 16:46:08 +03:00
|
|
|
Short: "Display or change the user identity.",
|
2019-02-17 18:12:06 +03:00
|
|
|
PreRunE: loadRepo,
|
|
|
|
RunE: runUser,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(userCmd)
|
|
|
|
userCmd.Flags().SortFlags = false
|
|
|
|
}
|