From cc600fe686e905a696cbc840decdd8d24b7bb72f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 12 Oct 2025 06:17:32 -0500 Subject: more cleaning --- history.go | 10 +++------- theMagicOfAutocomplete.go | 10 ++++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/history.go b/history.go index c048c1c..f26ba8e 100644 --- a/history.go +++ b/history.go @@ -11,12 +11,12 @@ import ( durationpb "google.golang.org/protobuf/types/known/durationpb" ) -func (newpb *Auto) getHistoryPB() error { +func (newpb *Auto) getHistoryPB() (*Autos, error) { all := NewAutos() err := config.LoadCache(all, "argv", newpb.Argname) // loads ~/.cache/argv/forge.pb if err != nil { // newpb.History = false - return err + return all, err } if all.Len() == 0 { @@ -25,10 +25,6 @@ func (newpb *Auto) getHistoryPB() error { err = all.Save() } - if newpb.Debug { - all.PrintHistory() - } - var last *Auto // find the last entry. this is dumb way to do it for found := range all.IterAll() { @@ -53,5 +49,5 @@ func (newpb *Auto) getHistoryPB() error { err = all.Save() newpb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err) - return err + return all, err } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index d28dd8b..3202af3 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -31,7 +31,14 @@ func Autocomplete(dest any) *Auto { pb.PrintDebug() } - pb.getHistoryPB() // read in the history protobuf file + all, err := pb.getHistoryPB() // read in the history protobuf file + if err != nil { + // there is no history + } + + if pb.Debug { + all.PrintHistory() + } // turn on debugging if duration < 200 milliseconds dur := pb.Duration.AsDuration() @@ -50,7 +57,6 @@ func Autocomplete(dest any) *Auto { } // pb.Debug = true // pb.Debugf("DEBUG: MustParse(%v)", flags) - var err error myAuto.pp, err = arg.ParseFlags(flags, dest) if err != nil { pb.Debugf("DEBUG: Parse error: %v", err) -- cgit v1.2.3