diff options
Diffstat (limited to 'history.go')
| -rw-r--r-- | history.go | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -11,28 +11,33 @@ import ( "go.wit.com/lib/cobol" "go.wit.com/lib/config" durationpb "google.golang.org/protobuf/types/known/durationpb" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) func (pb *Auto) getHistoryPB() error { all := NewAutos() err := config.LoadCache(all, "argv", pb.Argname) // loads ~/.cache/argv/forge.pb + if err != nil { + // pb.History = false + return err + } var last *Auto - if err == nil { - for found := range all.IterAll() { - dur := time.Since(found.Ctime.AsTime()) - pb.Duration = durationpb.New(dur) - // found.PrintDebug() - cmd := fmt.Sprintf("cmd='%s'", found.Cmd) - arglast := fmt.Sprintf("last='%s'", found.Last) - partial := fmt.Sprintf("p='%s'", found.Partial) - age := fmt.Sprintf("age='%-6.6s'", cobol.FormatDuration(dur)) - pb.Debugf("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs) - last = found - } + // find the last entry & print out debugging history + for found := range all.IterAll() { + cmd := fmt.Sprintf("cmd='%s'", found.Cmd) + arglast := fmt.Sprintf("last='%s'", found.Last) + partial := fmt.Sprintf("p='%s'", found.Partial) + dur := time.Since(found.Ctime.AsTime()) + age := fmt.Sprintf("age=(%s)", cobol.FormatDuration(dur)) + pb.Debugf("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs) + last = found } + // set the duration since the last auto complete + dur := time.Since(last.Ctime.AsTime()) + pb.Duration = durationpb.New(dur) + + // roll the autocomplete file if all.Len() > 15 { pb.Debugf("DEBUG: trim() history is over 100 len=%d vs new=%d", all.Len(), all.Len()-90) all.Autos = all.Autos[all.Len()-10:] @@ -47,10 +52,7 @@ func (pb *Auto) getHistoryPB() error { last = new(Auto) } - // this is the start time of the binary - now := time.Now() - pb.Ctime = timestamppb.New(now) - all.Append(pb) + all.Clone(pb) err = all.Save() pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err) |
