show.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package cmd
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/jsmartx/giter/git"
  6. "github.com/jsmartx/giter/store"
  7. "github.com/jsmartx/giter/util"
  8. "github.com/urfave/cli"
  9. )
  10. func Show(c *cli.Context) error {
  11. name := c.Args().First()
  12. if name == "" {
  13. g, err := git.New(".")
  14. if err == nil {
  15. if u := g.GetUser(); u != nil {
  16. name = u.Name
  17. }
  18. }
  19. if name == "" {
  20. name = util.Prompt(&util.PromptConfig{
  21. Prompt: "user name: ",
  22. })
  23. }
  24. }
  25. s := store.New()
  26. users := s.List(name, true)
  27. if len(users) == 0 {
  28. return errors.New("user not found")
  29. }
  30. for i, u := range users {
  31. keyPath, err := u.KeyPath()
  32. if err != nil {
  33. return err
  34. }
  35. if i == 0 {
  36. fmt.Println()
  37. }
  38. if u.IsSSH() {
  39. fmt.Printf(" User: %s\n", u.String())
  40. fmt.Printf(" Email: %s\n", u.Email)
  41. fmt.Printf("Private Key: %s\n", keyPath)
  42. fmt.Printf(" Public Key: %s.pub\n", keyPath)
  43. } else {
  44. fmt.Printf(" User: %s\n", u.String())
  45. fmt.Printf(" Email: %s\n", u.Email)
  46. fmt.Printf("Credential: %s.credential\n", keyPath)
  47. }
  48. fmt.Println()
  49. }
  50. return nil
  51. }