-
Notifications
You must be signed in to change notification settings - Fork 14
/
pia.go
53 lines (43 loc) · 1.12 KB
/
pia.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
package main
import (
"flag"
"os"
"os/exec"
"fmt"
"log"
)
var strBranch string
var syncPtr = flag.Bool("sync", false, "Sync subrepositories")
var branchPtr = flag.String("branch", "", "Switch git branch")
func main() {
flag.Parse()
strBranch = *branchPtr
flagset := make(map[string]bool)
flag.Visit(func(f *flag.Flag) { flagset[f.Name]=true } )
if len(os.Args) < 2 {
fmt.Println("At least one parameter is required. \n\nAvailable parameters:")
flag.PrintDefaults()
os.Exit(1)
}
if (flagset["sync"]) {
runCommand("git", []string{"status"});
if (len(strBranch) > 0) {
//change branch
runCommand("git", []string{"checkout", strBranch});
}
syncRepos();
}
}
func syncRepos() {
runCommand("git", []string{"submodule", "sync", "--recursive"});
runCommand("git", []string{"submodule", "update", "--init", "--recursive"});
}
func runCommand(command string, params []string) {
cmd := exec.Command(command, params...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
}