summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go54
1 files changed, 23 insertions, 31 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 0e92af3..a2ff7a9 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -80,8 +80,6 @@ func Autocomplete(dest any) *Argv {
savePB()
doAutocomplete()
panic("blah")
- savePB()
- saveAndExit()
}
// not autocompleting. return to the application
@@ -114,22 +112,6 @@ func doAutocomplete() {
// me.pb.PrintStderr()
}
- flags := []string{}
- for _, s := range me.pb.Real {
- if s == "--autodebug" {
- continue
- }
- if s == "--argvdebug" {
- me.pb.PrintStderr()
- continue
- }
- if strings.TrimSpace(s) == "" {
- // skip anything blank
- continue
- }
- flags = append(flags, s)
- }
-
if strings.HasPrefix(me.pb.Partial, "--argv") {
me.pb.SendString("--argvdebug --argvhelp")
me.pb.Stderr += fmt.Sprintln("argv override")
@@ -160,19 +142,19 @@ func doAutocomplete() {
me.pb.PrintStderrExit()
}
- if err := me.parseFlagsFunc(flags); err != nil {
+ if err := me.parseFlagsFunc(me.flags); err != nil {
me.pb.Stderr += fmt.Sprintf("application parseFlags() err(%v)\n", err)
me.pb.Stderr += fmt.Sprintln("argv.parseFlags() err. probably cmd doesn't really exist in struct")
me.debug = true
me.pb.PrintStderrExit()
}
- if len(flags) == 0 {
+ if len(me.flags) == 0 {
// error is normal if there are no command line args
} else {
if me.Err != nil {
// users has command line arguments that won't parse with go-args
- me.pb.Debugf("DEBUG: Parse error: %v flags%v", me.Err, flags)
+ me.pb.Debugf("DEBUG: Parse error: %v flags%v", me.Err, me.flags)
}
}
@@ -246,10 +228,8 @@ func examineArgvHistory() {
me.pb.PrintStderr()
panic("argvpb.Load() history file failed")
}
- me.all.PrintHistory("<?>")
- if me.all.Len() > 0 {
- last := me.all.Argvs[me.all.Len()-1]
- me.pb.Debugf("DEBUG LAST %v", last)
+ if me.debug {
+ // me.all.PrintHistory("EARLY")
}
// roll the autocomplete file
maxsize := 17
@@ -262,6 +242,8 @@ func examineArgvHistory() {
// newall.Autos = me.all.Autos[0:10]
}
+ // drops nil entries from the history
+ // todo: figure out why nil values are happening
counter := 0
for pb := range me.all.IterAll() {
counter += 1
@@ -269,28 +251,38 @@ func examineArgvHistory() {
me.all.Delete(pb)
continue
}
- hist := fmt.Sprintf("HISTNIL(%d)", counter)
- pb.PrintDebugNew(hist, "jwc")
+ // if me.debug {
+ // hist := fmt.Sprintf("HISTNIL(%d)", counter)
+ // pb.PrintDebugNew(hist, "too soon")
+ // }
}
+
+ // only have nil values in the .pb file. just die for now
if me.all.Len() == 0 {
me.pb.PrintStderr()
// todo: make a blak entry here
panic("examineArgvHistory() couldn't find a valid last entry")
}
+
+ // finally safe to get the last history entry
me.last = me.all.Argvs[me.all.Len()-1]
+ if me.debug {
+ me.all.PrintHistory(me.last.GetCmd())
+ }
// compute the duration since the last time
dur := time.Since(me.last.Ctime.AsTime())
me.pb.Duration = durationpb.New(dur)
- // turn on debugging if duration < 200 milliseconds
if me.pb.Duration.AsDuration() < time.Millisecond*200 {
- me.debug = true
me.pb.Fast = true
// me.fastcmd = me.pb.GetCmd()
if me.last.Fast {
- if me.pb.GetCmd() != me.last.GetCmd() {
- // do the smart something here
+ // do the smart something here
+ if me.pb.GetCmd() == me.last.GetCmd() {
+ // turn on debugging if duration < 200 milliseconds
+ // me.debug = false
+ } else {
}
}
}