submit-patchset/handleCmdLine.go

124 lines
2.7 KiB
Go
Raw Normal View History

package main
import (
"os"
2024-02-17 08:38:44 -06:00
"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
2024-02-17 08:38:44 -06:00
for _, repo := range repolist.AllRepos() {
2024-02-17 15:47:46 -06:00
log.Info("Running:", repo.Status.Path(), cmd)
2024-02-17 08:38:44 -06:00
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
2024-02-17 08:38:44 -06:00
for _, repo := range repolist.AllRepos() {
if repo.CheckDirty() {
2024-02-17 15:47:46 -06:00
log.Info("skipping dirty repo", repo.Name())
continue
}
2024-02-17 15:47:46 -06:00
branch := repo.Status.GetDevelBranchName()
cmd := []string{"git", "checkout", branch}
2024-02-17 15:47:46 -06:00
log.Info("Running:", cmd, "in", repo.Name())
2024-02-17 08:38:44 -06:00
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
2024-02-17 08:38:44 -06:00
for _, repo := range repolist.AllRepos() {
2024-02-17 15:47:46 -06:00
if repo.Status.CheckDirty() {
log.Info("skipping dirty repo", repo.Name())
continue
}
2024-02-17 15:47:46 -06:00
branch := repo.Status.GetUserBranchName()
cmd := []string{"git", "checkout", branch}
2024-02-17 15:47:46 -06:00
log.Info("Running:", cmd, "in", repo.Name())
2024-02-17 08:38:44 -06:00
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)
}
}