summaryrefslogtreecommitdiff
path: root/argv.Print.go
diff options
context:
space:
mode:
Diffstat (limited to 'argv.Print.go')
-rw-r--r--argv.Print.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/argv.Print.go b/argv.Print.go
new file mode 100644
index 0000000..d0a4447
--- /dev/null
+++ b/argv.Print.go
@@ -0,0 +1,60 @@
+package argvpb
+
+// debug argv protobuf functions
+// enable with --autodebug or Setenv( "AUTOCOMPLETE_VERBOSE" )
+
+import (
+ "fmt"
+ "os"
+ "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"
+ // 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 *Argv) PrintDebug() {
+ pb.PrintDebugNew("ARGV")
+}
+
+func (pb *Argv) PrintDebugNew(msg string) {
+ cmd := fmt.Sprintf("cmd='%s'", pb.Cmd)
+ arglast := fmt.Sprintf("last='%s'", pb.Last)
+ partial := fmt.Sprintf("p='%s'", pb.Partial)
+ dur := cobol.Duration(pb.Ctime)
+ var fast string
+ if pb.Fast {
+ fast = "fast=1," + pb.Fastcmd
+ } else {
+ fast = "fast=0," + pb.Fastcmd
+ }
+ 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")
+ }
+}
+
+// todo: fix this
+func (pb *Argv) WriteHelp() {
+ me.pp.WriteHelp(os.Stdout)
+}