diff options
| author | Jeff Carr <[email protected]> | 2025-10-25 09:03:31 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-25 09:03:31 -0500 |
| commit | 221839190ba296268926589dd50416c3e7cac24a (patch) | |
| tree | d2931fdefa42495bafad86b44c79e07da1508c3b | |
| parent | b95f2cab06e5de8fec71b0b991777f5d5cb1fa90 (diff) | |
something farther along?
| -rw-r--r-- | argv.Print.go | 5 | ||||
| -rw-r--r-- | argv.parseOsArgs.go | 32 | ||||
| -rw-r--r-- | structs.go | 9 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 54 |
4 files changed, 34 insertions, 66 deletions
diff --git a/argv.Print.go b/argv.Print.go index bb1de4a..2fcd859 100644 --- a/argv.Print.go +++ b/argv.Print.go @@ -41,7 +41,7 @@ func (pb *Argv) PrintDebugNew(msg string, last string) { 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) + top := fmt.Sprintf("%-4.4s age=(%s)dur(%s) h%2.2d %-12.12s %-12.12s", pb.Uuid, age, dur, pb.HelpCounter, cmd, arglast) Debugf("%s: %s %-12.12s %s %s goargs='%v' len(%d)", msg, top, partial, fast, sargv, pb.Goargs, me.all.Len()) } @@ -49,7 +49,8 @@ func (all *Argvs) PrintHistory(last string) { counter := 0 for pb := range all.IterAll() { counter += 1 - hist := fmt.Sprintf("HIST(%d)", counter) + // hist := fmt.Sprintf("HIST(%d)", counter) + hist := fmt.Sprintf("HIST") pb.PrintDebugNew(hist, last) } } diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go index 89750c9..d28e7e7 100644 --- a/argv.parseOsArgs.go +++ b/argv.parseOsArgs.go @@ -69,33 +69,11 @@ func (pb *Argv) parseOsArgs() { return } - // set debug flag if --argvdebug is passed - for _, s := range os.Args { - if s == "--argvdebug" { - me.debug = true - } - // deprecate - if s == "--autodebug" { - me.debug = true - } - } - - /* - // wtf is this. I've forgotten. todo: figure this out - if len(os.Args) > 1 && os.Args[1] == pb.AppInfo.APPNAME { - me.isAuto = true - // parts := strings.Split(os.Getenv("COMP_LINE"), " ") - me.debug = true - pb.Debugf("MATCH Partial os.Args=%v COMP_LINE=%v", os.Args, os.Getenv("COMP_LINE")) - os.Exit(0) - } - */ - // print the version and exit if len(os.Args) > 1 && os.Args[1] == "--version" { // if binary defined buildtime() then process standard version output here doVersion(pb) - os.Exit(0) + saveAndExit() } if os.Args[1] != "--auto-complete" { @@ -134,7 +112,8 @@ func (pb *Argv) parseOsArgs() { // pb.Argv = os.Args[4:] for _, s := range os.Args[4:] { - if s == "--autodebug" { + if s == "--argvdebug" { + me.debug = true continue } tmp := strings.Trim(pb.Partial, "'") @@ -144,10 +123,5 @@ func (pb *Argv) parseOsArgs() { } pb.Real = append(pb.Real, s) } - - // this is dumb - for _, s := range pb.Real { - pb.Goargs = append(pb.Goargs, s) - } return } @@ -8,6 +8,11 @@ type AutoArgs struct { pb *Argv // the protobuf for the current process all *Argvs // the history of argv last *Argv // the pb from the last time the user tried autocomplete + flags []string // notsure + Err error // store any errors from argv + debug bool // is dubugging on? + setupAuto bool // do shell autocomplete setup + isAuto bool // try to do autocomplete id int // should be unique Argv func([]string) // the function for shell autocomplete initArgvFunc func() (string, string, string) // this is required. gets APPNAME, BUILDTIME & VERSION @@ -23,8 +28,4 @@ type AutoArgs struct { buildtime func() (string, string) // some examples autoFunc func(*Argv) // also a function for autocomplete guiFunc func() error // enables Gui functions - Err error // store any errors from argv - debug bool // is dubugging on? - setupAuto bool // do shell autocomplete setup - isAuto bool // try to do autocomplete } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 0e92af3..a2ff7a9 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -80,8 +80,6 @@ func Autocomplete(dest any) *Argv { savePB() doAutocomplete() panic("blah") - savePB() - saveAndExit() } // not autocompleting. return to the application @@ -114,22 +112,6 @@ func doAutocomplete() { // me.pb.PrintStderr() } - flags := []string{} - for _, s := range me.pb.Real { - if s == "--autodebug" { - continue - } - if s == "--argvdebug" { - me.pb.PrintStderr() - continue - } - if strings.TrimSpace(s) == "" { - // skip anything blank - continue - } - flags = append(flags, s) - } - if strings.HasPrefix(me.pb.Partial, "--argv") { me.pb.SendString("--argvdebug --argvhelp") me.pb.Stderr += fmt.Sprintln("argv override") @@ -160,19 +142,19 @@ func doAutocomplete() { me.pb.PrintStderrExit() } - if err := me.parseFlagsFunc(flags); err != nil { + if err := me.parseFlagsFunc(me.flags); err != nil { me.pb.Stderr += fmt.Sprintf("application parseFlags() err(%v)\n", err) me.pb.Stderr += fmt.Sprintln("argv.parseFlags() err. probably cmd doesn't really exist in struct") me.debug = true me.pb.PrintStderrExit() } - if len(flags) == 0 { + if len(me.flags) == 0 { // error is normal if there are no command line args } else { if me.Err != nil { // users has command line arguments that won't parse with go-args - me.pb.Debugf("DEBUG: Parse error: %v flags%v", me.Err, flags) + me.pb.Debugf("DEBUG: Parse error: %v flags%v", me.Err, me.flags) } } @@ -246,10 +228,8 @@ func examineArgvHistory() { me.pb.PrintStderr() panic("argvpb.Load() history file failed") } - me.all.PrintHistory("<?>") - if me.all.Len() > 0 { - last := me.all.Argvs[me.all.Len()-1] - me.pb.Debugf("DEBUG LAST %v", last) + if me.debug { + // me.all.PrintHistory("EARLY") } // roll the autocomplete file maxsize := 17 @@ -262,6 +242,8 @@ func examineArgvHistory() { // newall.Autos = me.all.Autos[0:10] } + // drops nil entries from the history + // todo: figure out why nil values are happening counter := 0 for pb := range me.all.IterAll() { counter += 1 @@ -269,28 +251,38 @@ func examineArgvHistory() { me.all.Delete(pb) continue } - hist := fmt.Sprintf("HISTNIL(%d)", counter) - pb.PrintDebugNew(hist, "jwc") + // if me.debug { + // hist := fmt.Sprintf("HISTNIL(%d)", counter) + // pb.PrintDebugNew(hist, "too soon") + // } } + + // only have nil values in the .pb file. just die for now if me.all.Len() == 0 { me.pb.PrintStderr() // todo: make a blak entry here panic("examineArgvHistory() couldn't find a valid last entry") } + + // finally safe to get the last history entry me.last = me.all.Argvs[me.all.Len()-1] + if me.debug { + me.all.PrintHistory(me.last.GetCmd()) + } // compute the duration since the last time dur := time.Since(me.last.Ctime.AsTime()) me.pb.Duration = durationpb.New(dur) - // turn on debugging if duration < 200 milliseconds if me.pb.Duration.AsDuration() < time.Millisecond*200 { - me.debug = true me.pb.Fast = true // me.fastcmd = me.pb.GetCmd() if me.last.Fast { - if me.pb.GetCmd() != me.last.GetCmd() { - // do the smart something here + // do the smart something here + if me.pb.GetCmd() == me.last.GetCmd() { + // turn on debugging if duration < 200 milliseconds + // me.debug = false + } else { } } } |
