diff options
| author | Jeff Carr <[email protected]> | 2025-10-28 23:46:51 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-28 23:46:51 -0500 |
| commit | f3fa28a0a093c3e22ecacac914854523545d94f3 (patch) | |
| tree | 8636b15f76766c3acffc8ca251d61ec57d914007 | |
| parent | bca3f42ae8ddf7e56c93a143b915a8dc9f3326f4 (diff) | |
just make PB global until argv is worked out
| -rw-r--r-- | argv.print.go | 2 | ||||
| -rw-r--r-- | argv.version.go | 2 | ||||
| -rw-r--r-- | exit.go | 4 | ||||
| -rw-r--r-- | init.go | 8 | ||||
| -rw-r--r-- | structs.go | 1 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 62 |
6 files changed, 39 insertions, 40 deletions
diff --git a/argv.print.go b/argv.print.go index 49b1089..ed9edc2 100644 --- a/argv.print.go +++ b/argv.print.go @@ -20,7 +20,7 @@ func (pb *Argv) debugf(fmts string, parts ...any) { func debugf(fmts string, parts ...any) { fmts = strings.TrimSpace(fmts) fmts += "\n" - // me.pb.Stderr += fmt.Sprintf(fmts, parts...) + // PB.Stderr += fmt.Sprintf(fmts, parts...) fmt.Fprintf(Stddbg, fmts, parts...) } diff --git a/argv.version.go b/argv.version.go index 7882474..de8f759 100644 --- a/argv.version.go +++ b/argv.version.go @@ -40,5 +40,5 @@ func (info *App) getVersion() string { // deprecate ? func GetAPPNAME() string { - return me.pb.AppInfo.APPNAME + return PB.AppInfo.APPNAME } @@ -87,7 +87,7 @@ func ExitWatchdog() { return case t := <-dog.C: _ = t - fmt.Println("argv.Exit() watchdog: stalled in", me.pb.AppInfo.APPNAME+".Exit()") + fmt.Println("argv.Exit() watchdog: stalled in", PB.AppInfo.APPNAME+".Exit()") // h.Scan() } } @@ -111,7 +111,7 @@ func Defer(dur time.Duration, f func()) { return case t := <-dog.C: _ = t - fmt.Println("argv.Exit() watchdog: stalled in", me.pb.AppInfo.APPNAME+".Exit()") + fmt.Println("argv.Exit() watchdog: stalled in", PB.AppInfo.APPNAME+".Exit()") // h.Scan() } } @@ -11,14 +11,14 @@ import ( func Init(dest any, APPNAME string, anyString string, VERSION string) { me = new(AutoType) - me.pb = new(Argv) - PB = me.pb + PB = new(Argv) + me.all = NewArgvs() me.debug = true // set the start time of the binary now := time.Now() PB.Ctime = timestamppb.New(now) - me.pb.Uuid = uuid.New().String() // todo: add options to track this + PB.Uuid = uuid.New().String() // todo: add options to track this // needed by bash for autocomplete, help & debugging Stdout = NewStringWriter(&PB.Stdout) // bash uses this to match strings @@ -46,7 +46,7 @@ func Init(dest any, APPNAME string, anyString string, VERSION string) { app.BUILDTIME = anyString fmt.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, BUILDTIME, app.BUILDTIME) } - me.pb.AppInfo = app + PB.AppInfo = app // makes sure the application has the // needed functions defined, otherwise dies @@ -8,7 +8,6 @@ var PB *Argv // this is a work in progress type AutoType 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 Err error // store any errors from argv diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index c08df4b..7cb8194 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -22,16 +22,16 @@ import ( // - figures out what to print to Stdout & Stderr and then does os.Exit() func Autocomplete() *Argv { // parses os.Args into the protobuf - me.pb.parseOsArgs() + PB.parseOsArgs() // initializes the lib/env library - env.Init(me.pb.AppInfo.APPNAME, me.pb.AppInfo.VERSION, cobol.Time(me.pb.AppInfo.BUILDTIME), me.pb.Real, GoodExit, BadExit) + env.Init(PB.AppInfo.APPNAME, PB.AppInfo.VERSION, cobol.Time(PB.AppInfo.BUILDTIME), PB.Real, GoodExit, BadExit) // user is trying to setup bash or zsh autocomplete // --bash or --zsh is the first os.Args if me.setupAuto { // --bash or --zsh was passed. try to configure bash-completion - MakeAutocompleteFiles(me.pb.AppInfo.APPNAME) + MakeAutocompleteFiles(PB.AppInfo.APPNAME) // never forget to exit here or you will hate yourself and the choices you have made saveAndExit() } @@ -50,8 +50,8 @@ func Autocomplete() *Argv { // fmt.Println("no gui init") } - env.SetGlobal("argv", "real", fmt.Sprintf("%v", me.pb.Real)) - for _, a := range me.pb.Real { + env.SetGlobal("argv", "real", fmt.Sprintf("%v", PB.Real)) + for _, a := range PB.Real { if strings.HasPrefix(a, "--") { env.SetGlobal("argv", a, "true") } @@ -61,11 +61,11 @@ func Autocomplete() *Argv { // not autocompleting. return to the application me.Err = errors.Join(me.Err, me.mustParseFunc()) fmt.Fprintf(Stddbg, "did mustParseFunc(). heading to forge. err(%v)\n", me.Err) - me.pb.ErrCounter = 0 - me.pb.OutCounter = 0 + PB.ErrCounter = 0 + PB.OutCounter = 0 // save the pb & history. todo: remove this what things work. slow. disk i/o savePB() - return me.pb + return PB } fmt.Fprintf(Stddbg, "heading to autocomplete. err(%v)\n", me.Err) @@ -73,7 +73,7 @@ func Autocomplete() *Argv { // print to Stdout & Stderr saveAndExit() // never gets here - return me.pb + return PB } // doAutocomplete(): print what is needed to Stdout & Stderr, then exit @@ -83,26 +83,26 @@ func Autocomplete() *Argv { func prepareStdout() { if me.debug { // add an initial debug line - me.pb.printDebug(me.last.GetCmd()) + PB.printDebug(me.last.GetCmd()) } - if strings.HasPrefix(me.pb.Partial, "'--argv") { + if strings.HasPrefix(PB.Partial, "'--argv") { fmt.Fprintf(Stdout, " --argvdebug --argvhelp") - me.pb.Stddbg += fmt.Sprintln("argv override") + PB.Stddbg += fmt.Sprintln("argv override") me.debug = true return } // highjack "--gui" - if len(me.pb.Real) > 1 { - lastarg := me.pb.Real[len(me.pb.Real)-1] + if len(PB.Real) > 1 { + lastarg := PB.Real[len(PB.Real)-1] // this is a work in progress if lastarg == "--gui" { - me.pb.debugf("DEBUG: real=(%v) found --gui", me.pb.Real) + PB.debugf("DEBUG: real=(%v) found --gui", PB.Real) PB.Stdout += " andlabs gogui" return } else { - // me.pb.debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val) + // PB.debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val) } } @@ -117,8 +117,8 @@ func prepareStdout() { func savePB() { // save now. this is near the end probably dur := time.Since(PB.Ctime.AsTime()) - me.pb.ArgvDuration = durationpb.New(dur) // track how long autocomplete took - me.all.Append(me.pb) + PB.ArgvDuration = durationpb.New(dur) // track how long autocomplete took + me.all.Append(PB) // npb := new(Argv) // npb.Uuid = uuid.New().String() // me.all.Append(npb) @@ -160,7 +160,7 @@ func saveAndExit() { func examineArgvHistory() { me.all = NewArgvs() // loads the argv autocomplete history file - me.Err = config.ForceCreateCacheDirPB(me.all, "argv", me.pb.AppInfo.APPNAME) + me.Err = config.ForceCreateCacheDirPB(me.all, "argv", PB.AppInfo.APPNAME) if me.Err != nil { // there is no history. // ALWAYS KEEP THESE LINES AND THE panic() @@ -170,8 +170,8 @@ func examineArgvHistory() { // so this panic() is safe and can never be triggered by normal program execution. // me.debug = true - me.pb.Stddbg += fmt.Sprintf("config.CreateCacheDirPB() err(%v)\n", me.Err) - me.pb.Stddbg += fmt.Sprintf("argvpb.Load() history file failed") + PB.Stddbg += fmt.Sprintf("config.CreateCacheDirPB() err(%v)\n", me.Err) + PB.Stddbg += fmt.Sprintf("argvpb.Load() history file failed") printStderr() printStddbg() me.all = NewArgvs() @@ -186,7 +186,7 @@ func examineArgvHistory() { maxsize := 17 trim := 10 if me.all.Len() > maxsize { - me.pb.debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim) + PB.debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim) me.all.Argvs = me.all.Argvs[me.all.Len()-trim:] // newall.Autos = me.all.Autos[0:10] } @@ -237,25 +237,25 @@ func examineArgvHistory() { // compute the duration since the last time dur := time.Since(me.last.Ctime.AsTime()) - me.pb.Duration = durationpb.New(dur) + PB.Duration = durationpb.New(dur) - me.pb.ErrCounter = me.last.ErrCounter - me.pb.OutCounter = me.last.OutCounter + PB.ErrCounter = me.last.ErrCounter + PB.OutCounter = me.last.OutCounter // do the smart something here - if me.pb.GetCmd() == me.last.GetCmd() { + if PB.GetCmd() == me.last.GetCmd() { // turn on debugging if duration < 200 milliseconds } else { // reset counters if user types things - me.pb.OutCounter = 0 - me.pb.ErrCounter = 0 - me.pb.Fast = 0 + PB.OutCounter = 0 + PB.ErrCounter = 0 + PB.Fast = 0 } // user keeps hitting tab. trigger help if dur < time.Millisecond*300 { - me.pb.Fast = me.last.Fast + 1 + PB.Fast = me.last.Fast + 1 } else { - me.pb.Fast = 0 + PB.Fast = 0 errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application } } |
