diff options
| -rw-r--r-- | exit.go | 6 | ||||
| -rw-r--r-- | history.go | 54 | ||||
| -rw-r--r-- | structs.go | 4 |
3 files changed, 21 insertions, 43 deletions
@@ -5,7 +5,7 @@ import ( "os" "time" - "go.wit.com/lib/config" + "go.wit.com/lib/cobol" "go.wit.com/log" ) @@ -21,7 +21,7 @@ func (pb *Auto) GoodExit(msg string) { myAuto.appExit() } dur := time.Since(pb.Ctime.AsTime()) - log.Infof("%s: %s (%s)\n", pb.Argname, msg, config.FormatDuration(dur)) + log.Infof("%s: %s (%s)\n", pb.Argname, msg, cobol.FormatDuration(dur)) os.Exit(0) } @@ -34,7 +34,7 @@ func (pb *Auto) BadExit(msg string, err error) { log.Info(err) } dur := time.Since(pb.Ctime.AsTime()) - log.Infof("%s: %s (%s)\n", pb.Argname, msg, config.FormatDuration(dur)) + log.Infof("%s: %s (%s)\n", pb.Argname, msg, cobol.FormatDuration(dur)) os.Exit(-1) } @@ -6,42 +6,30 @@ package prep import ( "fmt" - "os" - "path/filepath" "time" + "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" ) -// makes a bash autocomplete file for your command func (pb *Auto) getHistoryPB() error { - cacheDir, err := os.UserCacheDir() - if err != nil { - return err - } - basedir := filepath.Join(cacheDir, "argv") - os.MkdirAll(basedir, os.ModePerm) - fullname := filepath.Join(basedir, pb.Argname+".pb") - all := NewAutos() + err := config.LoadCache(all, "argv", pb.Argname) // loads ~/.cache/argv/forge.pb + var last *Auto - data, err := os.ReadFile(fullname) if err == nil { - err = all.Unmarshal(data) - 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'", config.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 - } + 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 } } @@ -59,22 +47,12 @@ func (pb *Auto) getHistoryPB() error { last = new(Auto) } + // this is the start time of the binary now := time.Now() pb.Ctime = timestamppb.New(now) - duration := time.Since(last.Ctime.AsTime()) all.Append(pb) - data, err = all.Marshal() - if err != nil { - return err - } - - f, err := os.OpenFile(fullname, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) - defer f.Close() - if err != nil { - return err - } - _, err = f.Write(data) - pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d len(data)=%d dur=%v err=%v", fullname, all.Len(), len(data), duration, err) + err = all.Save() + pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err) return err } @@ -8,7 +8,7 @@ import ( "strings" "go.wit.com/dev/alexflint/arg" - "go.wit.com/lib/config" + "go.wit.com/lib/cobol" ) /* @@ -40,7 +40,7 @@ type AutoArgs struct { // print out auto complete debugging info func (pb *Auto) PrintDebug() { dur := pb.Duration.AsDuration() - pb.Debugf("AUTOCOMPLETE: arg0='%s' arg1='%s' partial='%s' cmd='%s' age=%s argv=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, config.FormatDuration(dur), pb.Argv) + pb.Debugf("AUTOCOMPLETE: arg0='%s' arg1='%s' partial='%s' cmd='%s' age=%s argv=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, cobol.FormatDuration(dur), pb.Argv) } func (pb *Auto) WriteHelp() { |
