-
Notifications
You must be signed in to change notification settings - Fork 0
/
batch.go
79 lines (66 loc) · 1.6 KB
/
batch.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
68
69
70
71
72
73
74
75
76
77
78
79
package gitcmd
import (
"path/filepath"
"github.com/gookit/gcli/v3"
"github.com/gookit/goutil/dump"
"github.com/inhere/kite-go/internal/biz/cmdbiz"
)
// BatchCmd command
var BatchCmd = &gcli.Command{
Name: "batch",
Aliases: []string{"bat"},
Desc: "provide some useful dev tools commands",
Subs: []*gcli.Command{
BatchRunCmd,
BatchPullCmd,
},
Config: func(c *gcli.Command) {
},
}
var btrOpts = struct {
cmdbiz.CommonOpts
pDir string
}{}
var BatchRunCmd = &gcli.Command{
Name: "run",
Desc: "batch run git command in the given dirs",
Aliases: []string{"exec"},
Config: func(c *gcli.Command) {
btrOpts.BindCommonFlags(c)
c.AddArg("dirs", "run command in the given dirs, if empty, run on all subdir")
},
Func: func(c *gcli.Command, args []string) error {
return nil
},
}
var btpOpts = struct {
cmdbiz.CommonOpts
dirs gcli.String
}{}
var BatchPullCmd = &gcli.Command{
Name: "pull",
Desc: "batch pull multi git directory by `git pull`",
Aliases: []string{"pul", "pl"},
Config: func(c *gcli.Command) {
c.
AddArg("baseDir", "base directory for run batch pull, default is work dir").
WithValue("./")
c.VarOpt(&btpOpts.dirs, "dirs", "", "limit update the given dir names")
},
Func: func(c *gcli.Command, args []string) error {
baseDir := c.Arg("baseDir").String()
absDir, err := filepath.Abs(baseDir)
if err != nil {
return err
}
dirNames := btpOpts.dirs.Split(",")
// if len(dirNames) > 0 {
// for _, name := range dirNames {
// path := filepath.Join(absDir, name)
// }
// return nil
// }
dump.P(dirNames, baseDir, absDir)
return nil
},
}