-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathselect.go
67 lines (56 loc) · 1.19 KB
/
select.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cmd
import (
"fmt"
"github.com/matsuyoshi30/gitsu/cmd/prompts"
"github.com/matsuyoshi30/gitsu/internal/config"
"github.com/matsuyoshi30/gitsu/internal/git"
"github.com/matsuyoshi30/gitsu/internal/models"
"github.com/urfave/cli/v2"
)
func SelectCommand() *cli.Command {
return &cli.Command{
Name: "select",
Aliases: []string{"s"},
Usage: "Select existing user",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "global",
Value: false,
Usage: "Set git user globally",
},
},
Action: func(c *cli.Context) error {
cfg, err := config.Read()
if err != nil {
return err
}
list := cfg.UserList()
if len(list) == 0 {
fmt.Println("No users")
return nil
}
index, _, err := prompts.SelectionCustom("Select git user", list)
if err != nil {
return err
}
user, err := cfg.SelectUser(index)
if err != nil {
return err
}
var scope = models.Local
if c.Bool("global") {
scope = models.Global
}
err = git.IsInsideWorktree(scope)
if err != nil {
return err
}
err = git.SetConfig(user, scope)
if err != nil {
return err
}
fmt.Printf("Setting profile %s", user.Format(0))
return nil
},
}
}