summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--complete.go15
-rw-r--r--doBuild.debian.go2
-rw-r--r--doBuild.go3
-rw-r--r--doGit.go84
-rw-r--r--main.go6
-rw-r--r--structs.go5
7 files changed, 62 insertions, 54 deletions
diff --git a/Makefile b/Makefile
index 54cde02..02520d8 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ VERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%s)
justinstall: install-verbose
+ wit --verbose
# This will re-generate ALL of the needed autogenerated .pb.go files
generate: clean
diff --git a/complete.go b/complete.go
index d18c642..aa45049 100644
--- a/complete.go
+++ b/complete.go
@@ -52,6 +52,13 @@ func (args) ArgvGui() error {
}
func (a args) DoAutoComplete() error {
+ var err error
+ me.pp, err = arg.ParseFlagsArgv(&argv)
+ if err != nil {
+ fmt.Fprintf(argvpb.Stddbg, "arg.ParseFlagsArgv finished autocomplete(%v)\n", err)
+ return nil
+ }
+
base := []string{"build", "upgrade", "git", "publish", "pb", "linux", "droplet", "test"}
base = append(base, "--version", "--force", "--all", "--dry-run", "--verbose")
@@ -73,14 +80,6 @@ func (a args) DoAutoComplete() error {
fmt.Fprintf(argvpb.Stdout, strings.Join(base, " "))
return nil
}
- var err error
- if me.pp == nil {
- me.pp, err = arg.ParseFlagsArgv(&argv)
- if err != nil {
- fmt.Fprintf(argvpb.Stderr, "returned from parseFlagsArgv(%v)\n", err)
- return err
- }
- }
err = me.pp.WriteHelpForAutocomplete(argvpb.PB.Partial, argvpb.PB.Real...)
fmt.Fprintf(argvpb.Stderr, "returned from WriteHelpForAutocomplete() pb.Real(%v)\n", argvpb.PB.Real)
fmt.Fprintf(argvpb.Stderr, "returned from WriteHelpForAutocomplete(%v)\n", err)
diff --git a/doBuild.debian.go b/doBuild.debian.go
index 80e3a4c..d6120c4 100644
--- a/doBuild.debian.go
+++ b/doBuild.debian.go
@@ -98,7 +98,7 @@ var totalBuilt int
func doBuildDeb(all *gitpb.Repos) (string, error) {
log.Info("STARTING DEBIAN PACKAGE BUILD")
// clean out old deb files
- globPattern := filepath.Join(me.homedir, "incoming", "*.deb")
+ globPattern := filepath.Join(env.Get("homedir"), "incoming", "*.deb")
files, err := filepath.Glob(globPattern)
if len(files) > 0 {
log.Info(files, err)
diff --git a/doBuild.go b/doBuild.go
index 3a5cb02..6bd70f8 100644
--- a/doBuild.go
+++ b/doBuild.go
@@ -10,6 +10,7 @@ import (
"strings"
"go.wit.com/lib/cobol"
+ "go.wit.com/lib/env"
"go.wit.com/lib/protobuf/argvpb"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
@@ -172,7 +173,7 @@ func doInstall(all *gitpb.Repos) error {
}
failed.Append(found)
}
- os.Remove(filepath.Join(me.homedir, "go/bin/forged"))
+ os.Remove(filepath.Join(env.Get("homedir"), "go/bin/forged"))
if failed.Len() > 0 {
for r := range failed.IterAll() {
log.Info("r.Namespace", r.Namespace)
diff --git a/doGit.go b/doGit.go
index 3ad057d..b2eaae0 100644
--- a/doGit.go
+++ b/doGit.go
@@ -11,6 +11,8 @@ import (
"strings"
"github.com/go-cmd/cmd"
+ "go.wit.com/lib/config"
+ "go.wit.com/lib/env"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/argvpb"
@@ -52,6 +54,23 @@ func runCommand(cmds []string) (string, error) {
func doGit() (string, error) {
var s string
var err error
+ var track []string
+
+ if env.Get("track") == "" {
+ env.Set("track", "~/.config/wit")
+ env.Save()
+ log.Info("Setting tracking on", env.Get("track"))
+ }
+
+ for _, p := range strings.Fields(env.Get("track")) {
+ fullp := env.FullPath(p)
+ if config.IsDir(fullp) {
+ log.Info("tracking repo:", fullp)
+ track = append(track, fullp)
+ } else {
+ log.Info("missing repo:", fullp)
+ }
+ }
if argv.Git.Log != nil {
fstr := "--format=\"%h %>(24)%ar %>(20)%an %s"
@@ -104,17 +123,20 @@ func doGit() (string, error) {
}
if argv.Git.Pull != nil {
- doPull(".config/wit")
- doPull("tools")
+ for _, fullp := range track {
+ doPull(fullp)
+ }
s = "git pull"
}
if argv.Git.Push != nil {
- doPush(".config/wit")
- doPush("tools")
- cmd := []string{"bwit", "git", "push"}
- s, err = runCommand(cmd)
- s = "git push"
+ for _, fullp := range track {
+ err := doPush(fullp)
+ if err != nil {
+ return "git push failed", err
+ }
+ }
+ s = "git push worked"
}
if argv.Git.DeleteUntracked {
@@ -150,52 +172,38 @@ func doGit() (string, error) {
return s, err
}
-func findRepo(wpath string) (*gitpb.Repo, bool) {
- d := filepath.Join(me.homedir, wpath)
- if !shell.IsDir(d) {
- return nil, false
- }
- repo, err := gitpb.NewRepo(d)
+func doPull(fpath string) error {
+ repo, err := gitpb.NewRepo(fpath)
if err != nil {
- log.Info("path error", d, err)
- return nil, false
- }
- return repo, true
-}
-
-func doPull(wpath string) {
- repo, ok := findRepo(wpath)
- if !ok {
- return
+ log.Info("path error", fpath, err)
+ return err
}
os.Chdir(repo.FullPath)
cmd := []string{"git", "pull"}
log.Info("Run", repo.FullPath, cmd)
- exitOnErrorRealtime(cmd)
+ err = repo.RunVerbose(cmd)
+ return err
}
-func doPush(wpath string) {
- doPull(wpath)
- d := filepath.Join(me.homedir, wpath)
- if !shell.IsDir(d) {
- return
- }
- repo, err := gitpb.NewRepo(d)
+func doPush(fpath string) error {
+ doPull(fpath)
+ repo, err := gitpb.NewRepo(fpath)
if err != nil {
- log.Info("path error", d, err)
- return
+ log.Info("path error", fpath, err)
+ return err
}
if repo == nil {
- log.Info("repo is nil", d, err)
- return
+ log.Info("repo is nil", fpath, err)
+ return errors.New("not git repo " + fpath)
}
if err := repo.GitCommit(); err != nil {
- msg := fmt.Sprintf("repo.GitCommit() %s", repo.FullPath)
- argvpb.BadExit(msg, err)
+ // msg := fmt.Sprintf("repo.GitCommit() %s err(%v)", repo.FullPath, err)
+ return err
}
- repo.RunRealtime([]string{"git", "push"})
+ err = repo.RunVerbose([]string{"git", "push"})
+ return err
}
/*
diff --git a/main.go b/main.go
index c25d5e5..3b707ff 100644
--- a/main.go
+++ b/main.go
@@ -8,6 +8,7 @@ import (
"os"
"unicode"
+ "go.wit.com/lib/env"
"go.wit.com/lib/protobuf/argvpb"
"go.wit.com/log"
)
@@ -18,7 +19,10 @@ var resources embed.FS
func main() {
me = new(mainType)
argvpb.Init(&argv, APPNAME, BUILDTIME, VERSION) // adds shell auto-complete
- me.homedir, _ = os.UserHomeDir() // store shortcut here todo: add better logic
+ env.LoadENV("~/.config/witrc")
+ if env.Verbose() {
+ env.PrintTable()
+ }
if argvpb.GetCmd() == "" {
// user didn't enter a sub command
diff --git a/structs.go b/structs.go
index 62fb875..aa71526 100644
--- a/structs.go
+++ b/structs.go
@@ -8,7 +8,6 @@ import (
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/debian"
- "go.wit.com/lib/env"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/protobuf/argvpb"
"go.wit.com/lib/protobuf/forgepb"
@@ -26,7 +25,6 @@ type mainType struct {
myGui *fhelp.GuiPrep // for initializing the GUI toolkits
forge *forgepb.Forge // your customized repo preferences and settings
machine *zoopb.Machine // your customized repo preferences and settings
- homedir string // where the user homedir is
}
func initForge() {
@@ -38,9 +36,6 @@ func initForge() {
}
me.forge.RescanRepos()
}
- if env.Verbose() {
- env.PrintTable()
- }
initMachine()
}