diff options
| -rw-r--r-- | doPatch.go | 22 | ||||
| -rw-r--r-- | main.go | 67 |
2 files changed, 51 insertions, 38 deletions
@@ -34,29 +34,29 @@ func isPatchingSafe() bool { return false } -func doPatch() error { +func doPatch() (string, error) { if argv.Patch.Submit != nil { - return doPatchSubmit() + return "Submitted", doPatchSubmit() } if !isPatchingSafe() { - return log.Errorf("not safe to work on patches") + return "not safe", errors.New("not safe to work on patches") } if argv.Patch.Get != nil { psets := forgepb.NewSets() newpb, _, _ := psets.HttpPostVerbose(myServer(), "get") - doPatchGet(newpb) - return nil + footer, err := doPatchGet(newpb) + return footer, err } if argv.Patch.List != nil { err := doPatchList() - return err + return "listed patches", err } err := doPatchList() - return err + return "listed patches. where is my footer?", err } // submit's current working patches @@ -153,7 +153,7 @@ func applyPatch(repo *gitpb.Repo, p *forgepb.Patch) (string, error) { return p.NewHash, log.Errorf("did not lookup new hash") } -func doPatchGet(newpb *forgepb.Sets) { +func doPatchGet(newpb *forgepb.Sets) (string, error) { // var changed bool curpatches := forgepb.NewPatches() curpatches.Filename = "/tmp/curpatches.pb" @@ -168,7 +168,6 @@ func doPatchGet(newpb *forgepb.Sets) { curpatches.Filename = "/tmp/curpatches.pb" curpatches.Save() } - // newpb.PrintTable() for pset := range newpb.IterAll() { if pset.Patches.Len() == 0 { log.Info("pset is empty", pset.Name) @@ -202,9 +201,8 @@ func doPatchGet(newpb *forgepb.Sets) { } } curpatches.Save() - curpatches.PrintTable() - // me.forge.Patchsets = newpb - // me.forge.Patchsets.Save() + footer := curpatches.PrintTable() + return footer, nil } var ErrorGitPullOnDirty error = errors.New("git comment is not there") @@ -39,6 +39,19 @@ func getVersion(repo *gitpb.Repo, name string) string { return strings.TrimSpace(output) } +func showUrls() bool { + if argv.Show == nil { + return false + } + if argv.Show.Repo == nil { + return false + } + if argv.Show.Repo.Urls != nil { + return true + } + return false +} + func main() { me = new(mainType) @@ -56,6 +69,18 @@ func main() { dumpDebug() } + if me.sh.Cmd == "" { + s, err := doDefaultBehavior() + if err != nil { + me.sh.BadExit(s, err) + } + me.sh.GoodExit(s) + } + + //// start standard argv subcommand processing here //// + + var s string + var err error if argv.Dev != nil { // first find the repos or gopaths to operate on if argv.Dev.Config != nil { @@ -172,10 +197,7 @@ func main() { } if argv.Patch != nil { - if err := doPatch(); err != nil { - badExit(err) - } - okExit("") + s, err = doPatch() } // open the gui unless the user performed some other @@ -190,42 +212,35 @@ func main() { debug() // sits here forever } + if err != nil { + me.sh.BadExit(s, err) + } + me.sh.GoodExit(s) +} + +func doDefaultBehavior() (string, error) { // DEFAULT BEHAVIOR CHANGES BETWEEN MODES if me.forge.Config.Mode == forgepb.ForgeMode_NORMAL || me.forge.Config.Mode == forgepb.ForgeMode_USER { // PROBABLY YOU ARE WRITING CODE // got to the end with nothing to do (?) if showWorkRepos() { // found some repos at least - } else { - // every repo is in a really clean state. no extra files anywhere - // no dirty repos, no repos that need to be published - // nothing different between user and master branch version. not common - log.Info("All of your git repositories appear to be in perfect shape") } - okExit("") + // every repo is in a really clean state. no extra files anywhere + // no dirty repos, no repos that need to be published + // nothing different between user and master branch version. not common + s := "All of your git repositories appear to be in perfect shape" + return s, nil } if me.forge.Config.Mode == forgepb.ForgeMode_MASTER { // PROBABLY YOU ARE PUBLISHING / MERGING CODE defaultBehaviorMaster() - okExit("") + return "default master behavior", nil } // PROBABLY A NEW USER found := findAll() - me.forge.PrintDefaultTB(found) - okExit("") -} - -func showUrls() bool { - if argv.Show == nil { - return false - } - if argv.Show.Repo == nil { - return false - } - if argv.Show.Repo.Urls != nil { - return true - } - return false + footer := me.forge.PrintDefaultTB(found) + return footer, nil } |
