-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-scan.go
More file actions
69 lines (56 loc) · 1.57 KB
/
Copy pathgit-scan.go
File metadata and controls
69 lines (56 loc) · 1.57 KB
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
package main
import (
"context"
"flag"
"predorock/gitscan/git"
"predorock/gitscan/logstreamer"
scanner "predorock/gitscan/scan"
"github.com/cristalhq/acmd"
)
var log = logstreamer.GetInstance().Log
type commonFlags struct {
parallel bool
}
// NOTE: should be added before flag.FlagSet method Parse().
func withCommonFlags(fs *flag.FlagSet) *commonFlags {
c := &commonFlags{}
fs.BoolVar(&c.parallel, "parallel", false, "run scan in parallel")
//fs.StringVar(&c.Dir, "dir", ".", "directory to process")
return c
}
func main() {
cmds := []acmd.Command{
{
Name: "update",
Description: "fetch and pull on current repo branch",
Do: func(ctx context.Context, args []string) error {
cmdFlags := flag.NewFlagSet("update", flag.ContinueOnError)
common := withCommonFlags(cmdFlags)
if err := cmdFlags.Parse(args); err != nil {
return err
}
for _, f := range cmdFlags.Args() {
log.Printf("Search for repos in folder %s\n", f)
if common.parallel {
scanner.ScanParallel(f, git.UpdateCommand)
} else {
scanner.Scan(f, git.UpdateCommand)
}
}
return nil
},
},
}
// all the acmd.Config fields are optional
r := acmd.RunnerOf(cmds, acmd.Config{
AppName: "gitscan",
AppDescription: "Do git stuff with multiple repos at the same time\nby Marco Predari <predorock@gmail.com>",
Version: "v0.0.1",
// Context - if nil `signal.Notify` will be used
// Args - if nil `os.Args[1:]` will be used
// Usage - if nil default print will be used
})
if err := r.Run(); err != nil {
r.Exit(err)
}
}