diff options
| -rw-r--r-- | argv.Match.go | 2 | ||||
| -rw-r--r-- | argv.Print.go | 28 | ||||
| -rw-r--r-- | argv.parseOsArgs.go | 4 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 53 |
4 files changed, 46 insertions, 41 deletions
diff --git a/argv.Match.go b/argv.Match.go index f8057c9..2039499 100644 --- a/argv.Match.go +++ b/argv.Match.go @@ -4,7 +4,7 @@ import "strings" func (pb *Argv) IsMatch(match string) bool { parts := strings.Split(match, ".") - pb.Debugf("IsMatch() parts (%v)", parts) + pb.debugf("IsMatch() parts (%v)", parts) for _, part := range parts { var found bool for _, v := range pb.Real { diff --git a/argv.Print.go b/argv.Print.go index a35d380..49b1089 100644 --- a/argv.Print.go +++ b/argv.Print.go @@ -12,12 +12,12 @@ import ( "go.wit.com/lib/config" ) -func (pb *Argv) Debugf(fmts string, parts ...any) { - Debugf(fmts, parts...) +func (pb *Argv) debugf(fmts string, parts ...any) { + debugf(fmts, parts...) } // decides here to print to STDERR or not -func Debugf(fmts string, parts ...any) { +func debugf(fmts string, parts ...any) { fmts = strings.TrimSpace(fmts) fmts += "\n" // me.pb.Stderr += fmt.Sprintf(fmts, parts...) @@ -25,11 +25,11 @@ func Debugf(fmts string, parts ...any) { } // print out auto complete debugging info -func (pb *Argv) PrintDebug(last string) { - pb.PrintDebugNew("ARGV", me.last) +func (pb *Argv) printDebug(last string) { + pb.printDebugNew("ARGV", me.last) } -func (pb *Argv) PrintDebugNew(msg string, last *Argv) { +func (pb *Argv) printDebugNew(msg string, last *Argv) { // var arglast string // arglast = fmt.Sprintf("last='%s'", last.GetCmd()) partial := fmt.Sprintf("p='%s'", pb.Partial) @@ -46,16 +46,16 @@ func (pb *Argv) PrintDebugNew(msg string, last *Argv) { lens := fmt.Sprintf("len=%-2d,%-2d,%-2d", me.all.Len(), len(strings.Fields(pb.Stdout)), len(strings.Split(pb.Stderr, "\n"))) fast := fmt.Sprintf("F%-2dout%-2derr%-2d %s", pb.Fast, pb.OutCounter, pb.ErrCounter, lens) top := fmt.Sprintf("%-4.4s age=(%s)(%s)dur(%s) %s %s cmd=%-12.12s", pb.Uuid, age, pdur, argvdur, dbg, fast, pb.GetCmd()) - Debugf("%s: %s %-12.12s real='%v'", msg, top, partial, pb.Real) + debugf("%s: %s %-12.12s real='%v'", msg, top, partial, pb.Real) } -func (all *Argvs) PrintHistory(msg string) { +func (all *Argvs) printHistory(msg string) { counter := 0 var last *Argv // for pb := range all.Argv[0:10] { for pb := range all.IterAll() { counter += 1 - pb.PrintDebugNew(msg, last) + pb.printDebugNew(msg, last) last = pb if counter > 30 { // sometimes I'm dumb @@ -64,12 +64,12 @@ func (all *Argvs) PrintHistory(msg string) { } } -func PrintStddbg() { +func printStddbg() { if !me.debug { return } if config.Exists("/tmp/argv.debug") { - PrintStddbgFile() + printStddbgFile() return } lines := strings.Split(strings.TrimSpace(PB.Stddbg), "\n") @@ -83,7 +83,7 @@ func PrintStddbg() { fmt.Fprintf(os.Stderr, "\n") } -func PrintStddbgFile() { +func printStddbgFile() { if !me.debug { return } @@ -103,7 +103,7 @@ func PrintStddbgFile() { fmt.Fprintf(f, "\n") } -func PrintStderr() { +func printStderr() { var lines []string for _, line := range strings.Split(strings.TrimSpace(PB.Stderr), "\n") { if strings.TrimSpace(line) == "" { @@ -125,7 +125,7 @@ func PrintStderr() { fmt.Fprintf(os.Stderr, "\n") } -func PrintStdout() { +func printStdout() { line := strings.TrimSpace(PB.Stdout) if line == "" { return diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go index 37a477d..12c63ac 100644 --- a/argv.parseOsArgs.go +++ b/argv.parseOsArgs.go @@ -47,10 +47,10 @@ func (pb *Argv) getSubSubCmd() string { for _, s := range pb.Real { p := fmt.Sprintf("'%s'", s) if pb.Partial == p { - pb.Debugf("DEBUG: Last argv MATCHES Partial %s %s", s, p) + pb.debugf("DEBUG: Last argv MATCHES Partial %s %s", s, p) continue } else { - pb.Debugf("DEBUG: Last argv DOES NOT MATCH Partial %s %s", s, p) + pb.debugf("DEBUG: Last argv DOES NOT MATCH Partial %s %s", s, p) } subcmd = s } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index e8a63ff..c08df4b 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -27,6 +27,15 @@ func Autocomplete() *Argv { // initializes the lib/env library env.Init(me.pb.AppInfo.APPNAME, me.pb.AppInfo.VERSION, cobol.Time(me.pb.AppInfo.BUILDTIME), me.pb.Real, GoodExit, BadExit) + // user is trying to setup bash or zsh autocomplete + // --bash or --zsh is the first os.Args + if me.setupAuto { + // --bash or --zsh was passed. try to configure bash-completion + MakeAutocompleteFiles(me.pb.AppInfo.APPNAME) + // never forget to exit here or you will hate yourself and the choices you have made + saveAndExit() + } + // open the argv cache history file to figure out the timing examineArgvHistory() @@ -41,15 +50,6 @@ func Autocomplete() *Argv { // fmt.Println("no gui init") } - // user is trying to setup bash or zsh autocomplete - // --bash or --zsh is the first os.Args - if me.setupAuto { - // --bash or --zsh was passed. try to configure bash-completion - MakeAutocompleteFiles(me.pb.AppInfo.APPNAME) - // never forget to exit here or you will hate yourself and the choices you have made - saveAndExit() - } - env.SetGlobal("argv", "real", fmt.Sprintf("%v", me.pb.Real)) for _, a := range me.pb.Real { if strings.HasPrefix(a, "--") { @@ -83,7 +83,7 @@ func Autocomplete() *Argv { func prepareStdout() { if me.debug { // add an initial debug line - me.pb.PrintDebug(me.last.GetCmd()) + me.pb.printDebug(me.last.GetCmd()) } if strings.HasPrefix(me.pb.Partial, "'--argv") { @@ -98,11 +98,11 @@ func prepareStdout() { lastarg := me.pb.Real[len(me.pb.Real)-1] // this is a work in progress if lastarg == "--gui" { - me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real) + me.pb.debugf("DEBUG: real=(%v) found --gui", me.pb.Real) PB.Stdout += " andlabs gogui" return } else { - // me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val) + // me.pb.debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val) } } @@ -127,14 +127,14 @@ func savePB() { func saveAndExit() { if me.debug { - me.all.PrintHistory("HIST") + me.all.printHistory("HIST") fmt.Fprintf(Stddbg, "me.debug=true pb.Stdout=(%v)\n", strings.TrimSpace(PB.Stdout)) - PrintStddbg() + printStddbg() } PB.ErrCounter += 1 if PB.ErrCounter < 3 { - PrintStderr() + printStderr() } else { if PB.ErrCounter > 10 { PB.ErrCounter = 0 @@ -142,7 +142,7 @@ func saveAndExit() { } PB.OutCounter += 1 - PrintStdout() + printStdout() if PB.OutCounter < 3 { } else { if PB.OutCounter > 5 { @@ -172,20 +172,21 @@ func examineArgvHistory() { me.debug = true me.pb.Stddbg += fmt.Sprintf("config.CreateCacheDirPB() err(%v)\n", me.Err) me.pb.Stddbg += fmt.Sprintf("argvpb.Load() history file failed") - PrintStderr() + printStderr() + printStddbg() me.all = NewArgvs() me.debug = true return } if me.debug { // use this if you are having trouble debugging this code - // me.all.PrintHistory("EARLY") + // me.all.printHistory("EARLY") } // roll the autocomplete file maxsize := 17 trim := 10 if me.all.Len() > maxsize { - me.pb.Debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim) + me.pb.debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim) me.all.Argvs = me.all.Argvs[me.all.Len()-trim:] // newall.Autos = me.all.Autos[0:10] } @@ -216,19 +217,23 @@ func examineArgvHistory() { // more early code for debugging if things go really wrong // if me.debug { // hist := fmt.Sprintf("HISTNIL(%d)", counter) - // pb.PrintDebugNew(hist, "too soon") + // pb.printDebugNew(hist, "too soon") // } } - // only have nil values in the .pb file. just die for now + // only have nil values in the .pb file. todo: figure out why this happens if me.all.Len() == 0 { me.debug = true fmt.Fprintf(Stddbg, "examineArgvHistory() empty file %s\n", me.all.Filename) - saveAndExit() + // saveAndExit() } - // finally safe to get the last history entry - me.last = me.all.Argvs[me.all.Len()-1] + // get the last autocomplete + if me.all.Len() == 0 { + me.last = new(Argv) + } else { + me.last = me.all.Argvs[me.all.Len()-1] + } // compute the duration since the last time dur := time.Since(me.last.Ctime.AsTime()) |
