|
@@ -3,7 +3,6 @@ package cmd
|
|
import (
|
|
import (
|
|
"errors"
|
|
"errors"
|
|
"fmt"
|
|
"fmt"
|
|
- "strconv"
|
|
|
|
|
|
|
|
"github.com/jsmartx/giter/git"
|
|
"github.com/jsmartx/giter/git"
|
|
"github.com/jsmartx/giter/store"
|
|
"github.com/jsmartx/giter/store"
|
|
@@ -12,57 +11,44 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
func Show(c *cli.Context) error {
|
|
func Show(c *cli.Context) error {
|
|
- g, err := git.New(".")
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
name := c.Args().First()
|
|
name := c.Args().First()
|
|
if name == "" {
|
|
if name == "" {
|
|
- defaultName := ""
|
|
|
|
- if u := g.GetUser(); u != nil {
|
|
|
|
- defaultName = u.Name
|
|
|
|
|
|
+ g, err := git.New(".")
|
|
|
|
+ if err == nil {
|
|
|
|
+ if u := g.GetUser(); u != nil {
|
|
|
|
+ name = u.Name
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if name == "" {
|
|
|
|
+ name = util.Prompt(&util.PromptConfig{
|
|
|
|
+ Prompt: "user name: ",
|
|
|
|
+ })
|
|
}
|
|
}
|
|
- name = util.Prompt(&util.PromptConfig{
|
|
|
|
- Prompt: "user name: ",
|
|
|
|
- Default: defaultName,
|
|
|
|
- })
|
|
|
|
}
|
|
}
|
|
s := store.New()
|
|
s := store.New()
|
|
users := s.List(name, true)
|
|
users := s.List(name, true)
|
|
if len(users) == 0 {
|
|
if len(users) == 0 {
|
|
return errors.New("user not found")
|
|
return errors.New("user not found")
|
|
}
|
|
}
|
|
- u := users[0]
|
|
|
|
- if len(users) > 1 {
|
|
|
|
- fmt.Printf("There are %d users:\n", len(users))
|
|
|
|
- for i, item := range users {
|
|
|
|
- fmt.Printf("%4d) %s\n", i+1, item.String())
|
|
|
|
- }
|
|
|
|
- str := util.Prompt(&util.PromptConfig{
|
|
|
|
- Prompt: "Enter number to select user: ",
|
|
|
|
- })
|
|
|
|
- i, err := strconv.Atoi(str)
|
|
|
|
|
|
+ for i, u := range users {
|
|
|
|
+ keyPath, err := u.KeyPath()
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
- if i < 1 || i > len(users) {
|
|
|
|
- return errors.New("Out of range")
|
|
|
|
|
|
+ if i == 0 {
|
|
|
|
+ fmt.Println()
|
|
}
|
|
}
|
|
- u = users[i-1]
|
|
|
|
- }
|
|
|
|
- keyPath, err := u.KeyPath()
|
|
|
|
- if err != nil {
|
|
|
|
- return err
|
|
|
|
- }
|
|
|
|
- if u.IsSSH() {
|
|
|
|
- fmt.Printf(" User: %s\n", u.String())
|
|
|
|
- fmt.Printf(" Email: %s\n", u.Email)
|
|
|
|
- fmt.Printf("Private Key: %s\n", keyPath)
|
|
|
|
- fmt.Printf(" Public Key: %s.pub\n", keyPath)
|
|
|
|
- } else {
|
|
|
|
- fmt.Printf(" User: %s\n", u.String())
|
|
|
|
- fmt.Printf(" Email: %s\n", u.Email)
|
|
|
|
- fmt.Printf("Credential: %s.credential\n", keyPath)
|
|
|
|
|
|
+ if u.IsSSH() {
|
|
|
|
+ fmt.Printf(" User: %s\n", u.String())
|
|
|
|
+ fmt.Printf(" Email: %s\n", u.Email)
|
|
|
|
+ fmt.Printf("Private Key: %s\n", keyPath)
|
|
|
|
+ fmt.Printf(" Public Key: %s.pub\n", keyPath)
|
|
|
|
+ } else {
|
|
|
|
+ fmt.Printf(" User: %s\n", u.String())
|
|
|
|
+ fmt.Printf(" Email: %s\n", u.Email)
|
|
|
|
+ fmt.Printf("Credential: %s.credential\n", keyPath)
|
|
|
|
+ }
|
|
|
|
+ fmt.Println()
|
|
}
|
|
}
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|