package prep // debug argv protobuf functions // enable with --autodebug or Setenv( "AUTOCOMPLETE_VERBOSE" ) import ( "fmt" "os" "strings" "time" "go.wit.com/lib/cobol" ) // decides here to print to STDERR or not func (pb *Auto) Debugf(fmts string, parts ...any) { fmts = strings.TrimSpace(fmts) fmts += "\n" // NOTE: env doesn't work probably most (all?) the time because bash // doesn't send all the ENV to autocomplete. so, trap on a "--autodebug" command line arg if os.Getenv("AUTOCOMPLETE_VERBOSE") == "true" || pb.Debug { if !pb.Newline { fmt.Fprintf(os.Stderr, "\n") pb.Newline = true } fmt.Fprintf(os.Stderr, fmts, parts...) } else { // fmt.Fprintf(os.Stderr, "NOT DOING ANYTHING\n") } } // print out auto complete debugging info func (pb *Auto) PrintDebug() { dur := pb.Duration.AsDuration() pb.Debugf("ARGV: 0='%s' 1='%s' p='%s' cmd='%s' age=(%s) argv=%v fast=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, cobol.FormatDuration(dur), pb.Argv, pb.Fast) } func (pb *Autos) PrintHistory() { for found := range pb.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)) found.Debugf("HIST: %s %-18.18s %-18.18s %-12.12s argv='%v' fast=%v goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Fast, found.Goargs) } } // todo: fix this func (pb *Auto) WriteHelp() { myAuto.pp.WriteHelp(os.Stdout) }