summaryrefslogtreecommitdiff
path: root/handleCmdLine.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-10 16:35:58 -0600
committerJeff Carr <[email protected]>2024-02-10 16:35:58 -0600
commit44e6fc669ed317173303affe13117aa16b09cd68 (patch)
treea8aeaa34e7cc35a6dbd0a58e9c6e623c60cb57ed /handleCmdLine.go
parentd590533ad55395991f66dd13d53215ebec3c68e7 (diff)
add command line options
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'handleCmdLine.go')
-rw-r--r--handleCmdLine.go122
1 files changed, 122 insertions, 0 deletions
diff --git a/handleCmdLine.go b/handleCmdLine.go
new file mode 100644
index 0000000..e49be8d
--- /dev/null
+++ b/handleCmdLine.go
@@ -0,0 +1,122 @@
+package main
+
+import (
+ "os"
+
+ "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 me.allrepos {
+ log.Info("Running:", repo.String(), cmd)
+ err, output := repo.status.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 me.allrepos {
+ if repo.status.CheckDirty() {
+ log.Info("skipping dirty repo", repo.String())
+ continue
+ }
+ branch := repo.status.GetDevelBranchName()
+ cmd := []string{"git", "checkout", branch}
+ log.Info("Running:", cmd, "in", repo.String())
+ err, output := repo.status.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 me.allrepos {
+ if repo.status.CheckDirty() {
+ log.Info("skipping dirty repo", repo.String())
+ continue
+ }
+ branch := repo.status.GetUserBranchName()
+ cmd := []string{"git", "checkout", branch}
+ log.Info("Running:", cmd, "in", repo.String())
+ err, output := repo.status.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)
+ }
+}