move common code to repolist
This commit is contained in:
parent
59ff2df1db
commit
9e6207ff38
41
args.go
41
args.go
|
@ -2,11 +2,12 @@ package main
|
|||
|
||||
/*
|
||||
this parses the command line arguements
|
||||
|
||||
this enables command line options from other packages like 'gui' and 'log'
|
||||
*/
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/debugger"
|
||||
"go.wit.com/lib/gui/logsettings"
|
||||
|
@ -40,3 +41,41 @@ func init() {
|
|||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// This will process the command line arguements after everything is initialized
|
||||
// If any of them are called, don't show the GUI at all and just exit.
|
||||
func handleCmdLine() {
|
||||
var doExit bool = false
|
||||
|
||||
if args.CheckoutDevel {
|
||||
me.autotypistWindow.Hide()
|
||||
me.repos.View.ArgCheckoutDevel()
|
||||
doExit = true
|
||||
} else {
|
||||
log.Info("not switching to devel branches")
|
||||
}
|
||||
|
||||
if args.CheckoutUser {
|
||||
me.autotypistWindow.Hide()
|
||||
me.repos.View.ArgCheckoutUser()
|
||||
doExit = true
|
||||
} else {
|
||||
log.Info("not switching to user branches")
|
||||
}
|
||||
|
||||
if args.GitPull {
|
||||
me.autotypistWindow.Hide()
|
||||
if me.repos.View.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)
|
||||
}
|
||||
}
|
||||
|
|
135
handleCmdLine.go
135
handleCmdLine.go
|
@ -1,135 +0,0 @@
|
|||
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.Status.ReadOnly() {
|
||||
// log.Info("skipping read-only", repo.Name())
|
||||
continue
|
||||
}
|
||||
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.ReadOnly() {
|
||||
// log.Info("skipping read-only", repo.Name())
|
||||
continue
|
||||
}
|
||||
if repo.Status.CheckDirty() {
|
||||
log.Info("skipping dirty repo", repo.Name())
|
||||
continue
|
||||
}
|
||||
branch := repo.Status.GetUserBranchName()
|
||||
if branch == repo.Status.GetCurrentBranchName() {
|
||||
// already on user branch
|
||||
continue
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue