summaryrefslogtreecommitdiff
path: root/handleCmdLine.go
blob: fdafcbe6ac4820c49a69de85d7057c4cc8469e82 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package main

import (
	"os"

	"go.wit.com/lib/gui/repolist"
	"go.wit.com/log"
)

/*
This will process the command line arguements like --git-pull

It should do them in a smart order. If any of them are called,
don't show the GUI at all and just exit.
*/

func argGitPull() bool {
	log.Info("running git pull everywhere")
	me.autotypistWindow.Hide()
	cmd := []string{"git", "pull"}
	var failed int = 0
	for _, repo := range repolist.AllRepos() {
		log.Info("Running:", repo.Status.Path(), cmd)
		err, output := repo.RunCmd(cmd)
		if err == nil {
			log.Info(output)
		} else {
			failed += 1
			log.Info("Something went wrong. Got err", err)
			log.Info("output =", output)
			return false
		}
	}
	log.Info("Ran git pull in all repos. failure count =", failed)
	return true
}

func argCheckoutDevel() bool {
	log.Info("running git checkout devel everwhere")
	me.autotypistWindow.Hide()
	var failed int = 0
	for _, repo := range repolist.AllRepos() {
		if repo.CheckDirty() {
			log.Info("skipping dirty repo", repo.Name())
			continue
		}
		branch := repo.Status.GetDevelBranchName()
		cmd := []string{"git", "checkout", branch}
		log.Info("Running:", cmd, "in", repo.Name())
		err, output := repo.RunCmd(cmd)
		if err == nil {
			log.Info("git checkout worked", output)
		} else {
			failed += 1
			log.Info("git checkout failed")
			log.Info("Something went wrong. Got err", err)
			log.Info("output =", output)
			// return false
		}
	}
	log.Info("Ran git checkout in all repos. failure count =", failed)
	return true
}

func argCheckoutUser() bool {
	log.Info("running git checkout devel everwhere")
	me.autotypistWindow.Hide()
	var failed int = 0
	for _, repo := range repolist.AllRepos() {
		if repo.Status.CheckDirty() {
			log.Info("skipping dirty repo", repo.Name())
			continue
		}
		branch := repo.Status.GetUserBranchName()
		cmd := []string{"git", "checkout", branch}
		log.Info("Running:", cmd, "in", repo.Name())
		err, output := repo.RunCmd(cmd)
		if err == nil {
			log.Info("git checkout worked", output)
		} else {
			failed += 1
			log.Info("git checkout failed")
			log.Info("Something went wrong. Got err", err)
			log.Info("output =", output)
			// return false
		}
	}
	log.Info("Ran git checkout in all repos. failure count =", failed)
	return true
}

func handleCmdLine() {
	var doExit bool = false

	if args.CheckoutDevel {
		argCheckoutDevel()
		doExit = true
	} else {
		log.Info("not switching to devel branches")
	}

	if args.CheckoutUser {
		argCheckoutUser()
		doExit = true
	} else {
		log.Info("not switching to user branches")
	}

	if args.GitPull {
		if argGitPull() {
			log.Info("git pull everywhere worked")
		} else {
			log.Info("git failed somewhere")
		}
		doExit = true
	} else {
		log.Info("not running git pull everywhere")
	}

	if doExit {
		os.Exit(0)
	}
}