summaryrefslogtreecommitdiff
path: root/argv.Print.go
blob: 9429a01403545e684737061d7c4f552cbf605c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package argvpb

// debug argv protobuf functions
// enable with --autodebug or Setenv( "AUTOCOMPLETE_VERBOSE" )

import (
	"fmt"
	"strings"

	"go.wit.com/lib/cobol"
)

// decides here to print to STDERR or not
func (pb *Argv) Debugf(fmts string, parts ...any) {
	fmts = strings.TrimSpace(fmts)
	fmts += "\n"
	pb.Stderr += fmt.Sprintf(fmts, parts...)
}

// print out auto complete debugging info
func (pb *Argv) PrintDebug() {
	pb.PrintDebugNew("ARGV")
}

func (pb *Argv) PrintDebugNew(msg string) {
	cmd := fmt.Sprintf("cmd='%s'", pb.GetCmd())
	var arglast string
	if me.last == nil {
		arglast = fmt.Sprintf("last='%s'", "<nil>")
	} else {
		arglast = fmt.Sprintf("last='%s'", me.last.GetCmd())
	}
	partial := fmt.Sprintf("p='%s'", pb.Partial)
	dur := cobol.Duration(pb.Ctime)
	var fast string
	if pb.Fast {
		fast = "fast=1," + pb.GetCmd()
	} else {
		fast = "fast=0," + pb.GetCmd()
	}
	sargv := fmt.Sprintf("argv(%v)", pb.Real)
	pb.Debugf("%s: age=(%s) %-12.12s %-12.12s %-12.12s %s %s goargs='%v'", msg, dur, cmd, arglast, partial, fast, sargv, pb.Goargs)
}

func (all *Argvs) PrintHistory() {
	for pb := range all.IterAll() {
		pb.PrintDebugNew("HIST")
	}
}