package argvpb // debug argv protobuf functions // enable with --autodebug or Setenv( "AUTOCOMPLETE_VERBOSE" ) import ( "fmt" "os" "strings" "go.wit.com/lib/cobol" ) func (pb *Argv) Debugf(fmts string, parts ...any) { Debugf(fmts, parts...) } // decides here to print to STDERR or not func Debugf(fmts string, parts ...any) { fmts = strings.TrimSpace(fmts) fmts += "\n" me.pb.Stderr += fmt.Sprintf(fmts, parts...) } // print out auto complete debugging info func (pb *Argv) PrintDebug(last string) { pb.PrintDebugNew("ARGV", last) } func (pb *Argv) PrintDebugNew(msg string, last string) { cmd := fmt.Sprintf("cmd='%s'", pb.GetCmd()) var arglast string arglast = fmt.Sprintf("last='%s'", last) partial := fmt.Sprintf("p='%s'", pb.Partial) age := cobol.Duration(pb.Ctime) dur := cobol.Duration(pb.Duration) var fast string if pb.Fast { fast = "fast=1," + pb.GetCmd() } else { fast = "fast=0," + pb.GetCmd() } sargv := fmt.Sprintf("argv(%v)", pb.Real) top := fmt.Sprintf("age=(%s)dur(%s)%-4.4s %-12.12s %-12.12s", age, dur, pb.Uuid, cmd, arglast) Debugf("%s: %s %-12.12s %s %s goargs='%v' len(%d)", msg, top, partial, fast, sargv, pb.Goargs, me.all.Len()) } func (all *Argvs) PrintHistory(last string) { counter := 0 for pb := range all.IterAll() { counter += 1 hist := fmt.Sprintf("HIST(%d)", counter) pb.PrintDebugNew(hist, last) } } func (pb *Argv) PrintStderr() { if !me.debug { os.Exit(0) } lines := strings.Split(strings.TrimSpace(pb.Stderr), "\n") if len(lines) == 0 { os.Exit(0) } fmt.Fprintf(os.Stderr, "\n") for _, line := range lines { line = strings.TrimSpace(line) if line == "" { continue } fmt.Fprintf(os.Stderr, "%s\n", line) } } func (pb *Argv) PrintStdout() { fmt.Fprintf(os.Stdout, "%s\n", pb.Stdout) } func (pb *Argv) PrintStderrExit() { pb.PrintStderr() pb.PrintStdout() os.Exit(0) } func (pb *Argv) PrintStdoutExit() { pb.PrintStdout() os.Exit(0) }