From e27e1716d77f4d4f09d89285707895724e7a3838 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 8 Jan 2025 05:47:33 -0600 Subject: better filenames --- argvAutocomplete.go | 98 ---------------------------------- argvAutoshell.go | 98 ++++++++++++++++++++++++++++++++++ doCheckout.go | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++ doCommon.go | 148 ---------------------------------------------------- 4 files changed, 246 insertions(+), 246 deletions(-) delete mode 100644 argvAutocomplete.go create mode 100644 argvAutoshell.go create mode 100644 doCheckout.go delete mode 100644 doCommon.go diff --git a/argvAutocomplete.go b/argvAutocomplete.go deleted file mode 100644 index 1d4b8cf..0000000 --- a/argvAutocomplete.go +++ /dev/null @@ -1,98 +0,0 @@ -package main - -import ( - "fmt" - "os" -) - -/* - handles shell autocomplete -*/ - -// used for shell auto completion -// var ARGNAME string = "forge" // todo: get this from $0 ? - -func (a *EmptyCmd) deleteMatch() { - fmt.Println("go.wit.com/lib/gui/repostatus") -} - -func (args) doBashAuto() { - argv.doBashHelp() - switch argv.BashAuto[0] { - case "checkout": - fmt.Println("user devel master") - case "config": - fmt.Println("add fix list delete") - case "list": - fmt.Println("--all --mine --favorites --private") - case "pull": - fmt.Println("--all --mine --favorites --private") - case "patch": - fmt.Println("--list --submit --show") - case "dirty": - case "user": - fmt.Println("--force") - case "devel": - fmt.Println("--force") - case "master": - fmt.Println("--force") - case "delete": - argv.Delete.deleteMatch() - default: - if argv.BashAuto[0] == ARGNAME { - // list the subcommands here - fmt.Println("--bash --show checkout config dirty delete hard-reset list patch pull rescan") - } - } - os.Exit(0) -} - -// prints help to STDERR // TODO: move everything below this to go-args -func (args) doBashHelp() { - if argv.BashAuto[1] != "''" { - // if this is not blank, then the user has typed something - return - } - if argv.BashAuto[0] != ARGNAME { - // if this is not the name of the command, the user already started doing something - return - } - if argv.BashAuto[0] == ARGNAME { - me.pp.WriteHelp(os.Stderr) - return - } - fmt.Fprintln(os.Stderr, "") - fmt.Fprintln(os.Stderr, "hello world") - fmt.Fprintln(os.Stderr, "") -} - -// complete -F forge --bash forge -func (args) doBash() { - fmt.Println("# add this in your bashrc:") - fmt.Println("") - fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash") - fmt.Println("#") - fmt.Println("# todo: make this output work/parse with:") - fmt.Println("# complete -C " + ARGNAME + " --bash go") - fmt.Println("") - fmt.Println("_" + ARGNAME + "_complete()") - fmt.Println("{") - fmt.Println(" # sets local to this func vars") - fmt.Println(" local cur prev all") - fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}") - fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}") - fmt.Println(" all=${COMP_WORDS[@]}") - fmt.Println("") - fmt.Println(" # this is where we generate the go-arg output") - fmt.Println(" GOARGS=$(" + ARGNAME + " --auto-complete $prev \\'$cur\\' $all)") - fmt.Println("") - fmt.Println(" # this compares the command line input from the user") - fmt.Println(" # to whatever strings we output") - fmt.Println(" COMPREPLY=( $(compgen -W \"$GOARGS\" -- $cur) ) # THIS WORKS") - fmt.Println(" return 0") - fmt.Println("}") - fmt.Println("complete -F _" + ARGNAME + "_complete " + ARGNAME) - fmt.Println("") - fmt.Println("# copy and paste the above into your bash shell should work") - os.Exit(0) -} diff --git a/argvAutoshell.go b/argvAutoshell.go new file mode 100644 index 0000000..1d4b8cf --- /dev/null +++ b/argvAutoshell.go @@ -0,0 +1,98 @@ +package main + +import ( + "fmt" + "os" +) + +/* + handles shell autocomplete +*/ + +// used for shell auto completion +// var ARGNAME string = "forge" // todo: get this from $0 ? + +func (a *EmptyCmd) deleteMatch() { + fmt.Println("go.wit.com/lib/gui/repostatus") +} + +func (args) doBashAuto() { + argv.doBashHelp() + switch argv.BashAuto[0] { + case "checkout": + fmt.Println("user devel master") + case "config": + fmt.Println("add fix list delete") + case "list": + fmt.Println("--all --mine --favorites --private") + case "pull": + fmt.Println("--all --mine --favorites --private") + case "patch": + fmt.Println("--list --submit --show") + case "dirty": + case "user": + fmt.Println("--force") + case "devel": + fmt.Println("--force") + case "master": + fmt.Println("--force") + case "delete": + argv.Delete.deleteMatch() + default: + if argv.BashAuto[0] == ARGNAME { + // list the subcommands here + fmt.Println("--bash --show checkout config dirty delete hard-reset list patch pull rescan") + } + } + os.Exit(0) +} + +// prints help to STDERR // TODO: move everything below this to go-args +func (args) doBashHelp() { + if argv.BashAuto[1] != "''" { + // if this is not blank, then the user has typed something + return + } + if argv.BashAuto[0] != ARGNAME { + // if this is not the name of the command, the user already started doing something + return + } + if argv.BashAuto[0] == ARGNAME { + me.pp.WriteHelp(os.Stderr) + return + } + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "hello world") + fmt.Fprintln(os.Stderr, "") +} + +// complete -F forge --bash forge +func (args) doBash() { + fmt.Println("# add this in your bashrc:") + fmt.Println("") + fmt.Println("# todo: add this to go-arg as a 'hidden' go-arg option --bash") + fmt.Println("#") + fmt.Println("# todo: make this output work/parse with:") + fmt.Println("# complete -C " + ARGNAME + " --bash go") + fmt.Println("") + fmt.Println("_" + ARGNAME + "_complete()") + fmt.Println("{") + fmt.Println(" # sets local to this func vars") + fmt.Println(" local cur prev all") + fmt.Println(" cur=${COMP_WORDS[COMP_CWORD]}") + fmt.Println(" prev=${COMP_WORDS[COMP_CWORD-1]}") + fmt.Println(" all=${COMP_WORDS[@]}") + fmt.Println("") + fmt.Println(" # this is where we generate the go-arg output") + fmt.Println(" GOARGS=$(" + ARGNAME + " --auto-complete $prev \\'$cur\\' $all)") + fmt.Println("") + fmt.Println(" # this compares the command line input from the user") + fmt.Println(" # to whatever strings we output") + fmt.Println(" COMPREPLY=( $(compgen -W \"$GOARGS\" -- $cur) ) # THIS WORKS") + fmt.Println(" return 0") + fmt.Println("}") + fmt.Println("complete -F _" + ARGNAME + "_complete " + ARGNAME) + fmt.Println("") + fmt.Println("# copy and paste the above into your bash shell should work") + os.Exit(0) +} diff --git a/doCheckout.go b/doCheckout.go new file mode 100644 index 0000000..eb48c04 --- /dev/null +++ b/doCheckout.go @@ -0,0 +1,148 @@ +package main + +import ( + "time" + + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/forgepb" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func doGitPull() { + allerr := me.found.RillGitPull(40, 5) + + all := me.found.SortByFullPath() + for all.Scan() { + repo := all.Next() + result := allerr[repo] + if result.Error == gitpb.ErrorGitPullOnDirty { + log.Info("skip git pull. repo is dirty", repo.GetGoPath()) + continue + } + if result.Error == gitpb.ErrorGitPullOnLocal { + log.Info("skip git pull. local branch ", repo.GetGoPath()) + continue + } + if result.Exit == 0 { + continue + } + + log.Info("git pull error:", repo.GetGoPath(), result.Error) + log.Info("git pull error:", repo.GetGoPath(), result.Stdout) + } + +} + +func doCheckDirtyAndConfigSave() { + var count int + now := time.Now() + all := me.found.SortByFullPath() + for all.Scan() { + repo := all.Next() + dirty := repo.IsDirty() + if repo.CheckDirty() { + count += 1 + me.found.AppendUniqueGoPath(repo) + if !dirty { + configSave = true + } + } else { + if dirty { + configSave = true + } + } + } + log.Printf("dirty check %d took:%s\n", count, shell.FormatDuration(time.Since(now))) + me.forge.SetConfigSave(configSave) +} + +func IsEverythingOnDevel() bool { + me.found = new(gitpb.Repos) + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { + // log.Info(repo.GetFullPath(), repo.GetCurrentBranchName(), repo.GetDevelBranchName()) + me.found.AppendUniqueGoPath(repo) + } + } + if len(me.found.Repos) == 0 { + return true + } + return false +} + +func IsEverythingOnUser() bool { + me.found = new(gitpb.Repos) + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + if repo.GetCurrentBranchName() != repo.GetUserBranchName() { + me.found.AppendUniqueGoPath(repo) + } + } + if len(me.found.Repos) == 0 { + return true + } + return false +} + +func doGitReset() { + all := me.found.SortByFullPath() + for all.Scan() { + repo := all.Next() + if me.forge.Config.IsReadOnly(repo.GetGoPath()) { + // log.Info("is readonly", repo.GetGoPath()) + if repo.CheckDirty() { + log.Info("is readonly and dirty", repo.GetGoPath()) + cmd := []string{"git", "reset", "--hard"} + repo.RunRealtime(cmd) + } + } else { + // log.Info("is not readonly", repo.GetGoPath()) + } + } +} + +func checkoutBranches(repo *gitpb.Repo) error { + dname := repo.GetDevelBranchName() + if dname == "" { + if err := me.forge.MakeDevelBranch(repo); err != nil { + log.Info("verify() no devel branch name", repo.GetGoPath()) + return err + } + configSave = true + } + if repo.GetUserBranchName() == "" { + if err := me.forge.MakeUserBranch(repo); err != nil { + log.Info("verify() no devel branch name", repo.GetGoPath()) + return err + } + configSave = true + } + return nil +} + +func doAllCheckoutDevel() bool { + me.forge.CheckoutDevel() + me.forge = forgepb.Init() + if !IsEverythingOnDevel() { + log.Info("switching to devel branch failed") + me.forge.PrintHumanTable(me.found) + badExit(nil) + return false + } + return true +} + +func doAllCheckoutUser() bool { + me.forge.CheckoutUser() + me.forge = forgepb.Init() + if !IsEverythingOnUser() { + log.Info("switching to user branch failed") + me.forge.PrintHumanTable(me.found) + return false + } + return true +} diff --git a/doCommon.go b/doCommon.go deleted file mode 100644 index eb48c04..0000000 --- a/doCommon.go +++ /dev/null @@ -1,148 +0,0 @@ -package main - -import ( - "time" - - "go.wit.com/lib/gui/shell" - "go.wit.com/lib/protobuf/forgepb" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -func doGitPull() { - allerr := me.found.RillGitPull(40, 5) - - all := me.found.SortByFullPath() - for all.Scan() { - repo := all.Next() - result := allerr[repo] - if result.Error == gitpb.ErrorGitPullOnDirty { - log.Info("skip git pull. repo is dirty", repo.GetGoPath()) - continue - } - if result.Error == gitpb.ErrorGitPullOnLocal { - log.Info("skip git pull. local branch ", repo.GetGoPath()) - continue - } - if result.Exit == 0 { - continue - } - - log.Info("git pull error:", repo.GetGoPath(), result.Error) - log.Info("git pull error:", repo.GetGoPath(), result.Stdout) - } - -} - -func doCheckDirtyAndConfigSave() { - var count int - now := time.Now() - all := me.found.SortByFullPath() - for all.Scan() { - repo := all.Next() - dirty := repo.IsDirty() - if repo.CheckDirty() { - count += 1 - me.found.AppendUniqueGoPath(repo) - if !dirty { - configSave = true - } - } else { - if dirty { - configSave = true - } - } - } - log.Printf("dirty check %d took:%s\n", count, shell.FormatDuration(time.Since(now))) - me.forge.SetConfigSave(configSave) -} - -func IsEverythingOnDevel() bool { - me.found = new(gitpb.Repos) - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { - // log.Info(repo.GetFullPath(), repo.GetCurrentBranchName(), repo.GetDevelBranchName()) - me.found.AppendUniqueGoPath(repo) - } - } - if len(me.found.Repos) == 0 { - return true - } - return false -} - -func IsEverythingOnUser() bool { - me.found = new(gitpb.Repos) - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetUserBranchName() { - me.found.AppendUniqueGoPath(repo) - } - } - if len(me.found.Repos) == 0 { - return true - } - return false -} - -func doGitReset() { - all := me.found.SortByFullPath() - for all.Scan() { - repo := all.Next() - if me.forge.Config.IsReadOnly(repo.GetGoPath()) { - // log.Info("is readonly", repo.GetGoPath()) - if repo.CheckDirty() { - log.Info("is readonly and dirty", repo.GetGoPath()) - cmd := []string{"git", "reset", "--hard"} - repo.RunRealtime(cmd) - } - } else { - // log.Info("is not readonly", repo.GetGoPath()) - } - } -} - -func checkoutBranches(repo *gitpb.Repo) error { - dname := repo.GetDevelBranchName() - if dname == "" { - if err := me.forge.MakeDevelBranch(repo); err != nil { - log.Info("verify() no devel branch name", repo.GetGoPath()) - return err - } - configSave = true - } - if repo.GetUserBranchName() == "" { - if err := me.forge.MakeUserBranch(repo); err != nil { - log.Info("verify() no devel branch name", repo.GetGoPath()) - return err - } - configSave = true - } - return nil -} - -func doAllCheckoutDevel() bool { - me.forge.CheckoutDevel() - me.forge = forgepb.Init() - if !IsEverythingOnDevel() { - log.Info("switching to devel branch failed") - me.forge.PrintHumanTable(me.found) - badExit(nil) - return false - } - return true -} - -func doAllCheckoutUser() bool { - me.forge.CheckoutUser() - me.forge = forgepb.Init() - if !IsEverythingOnUser() { - log.Info("switching to user branch failed") - me.forge.PrintHumanTable(me.found) - return false - } - return true -} -- cgit v1.2.3