diff options
Diffstat (limited to 'theMagicOfAutocomplete.go')
| -rw-r--r-- | theMagicOfAutocomplete.go | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 3f2311f..94fb38c 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -63,7 +63,7 @@ func Autocomplete(dest any) *Argv { // user is trying to setup bash or zsh autocomplete // --bash or --zsh is the first os.Args - if me.pb.SetupAuto { + if me.setupAuto { // --bash or --zsh was passed. try to configure bash-completion MakeAutocompleteFiles(me.pb.AppInfo.APPNAME) // never forget to run this our you will hate yourself and the choices you have made @@ -78,7 +78,7 @@ func Autocomplete(dest any) *Argv { } // not autocompleting. return go-arg & the application - if !me.pb.IsAuto { + if !me.isAuto { // save the pb & history all.Clone(me.pb) errors.Join(err, all.Save()) @@ -93,15 +93,15 @@ func Autocomplete(dest any) *Argv { // set the duration since the last auto complete // find the last entry. this is dumb way to do it - last := new(Argv) - last.Ctime = timestamppb.New(time.Now().Add(-time.Second)) + me.last = new(Argv) + me.last.Ctime = timestamppb.New(time.Now().Add(-time.Second)) for found := range all.IterAll() { - last = found + me.last = found } - dur := time.Since(last.Ctime.AsTime()) + dur := time.Since(me.last.Ctime.AsTime()) me.pb.Duration = durationpb.New(dur) - if me.pb.Debug { + if me.debug { // dump debug info me.pb.PrintDebug() all.PrintHistory() @@ -120,11 +120,11 @@ func Autocomplete(dest any) *Argv { // turn on debugging if duration < 200 milliseconds dur = me.pb.Duration.AsDuration() if dur < time.Millisecond*200 { - me.pb.Debug = true + me.debug = true me.pb.Fast = true - me.pb.Fastcmd = me.pb.Cmd - if last.Fast { - if me.pb.Fastcmd == last.Fastcmd { + // me.fastcmd = me.pb.GetCmd() + if me.last.Fast { + if me.pb.GetCmd() == me.last.GetCmd() { // do the smart something here } } @@ -142,7 +142,7 @@ func Autocomplete(dest any) *Argv { flags = append(flags, s) } - if strings.HasPrefix(me.pb.Last, "--argv") { + if strings.HasPrefix(me.pb.Partial, "--argv") { me.pb.SendString("--argvdebug --argvhelp") os.Exit(0) } @@ -171,26 +171,27 @@ func Autocomplete(dest any) *Argv { all.Clone(me.pb) errors.Join(err, all.Save()) + lastarg := me.pb.Real[len(me.pb.Real)-1] // this is a work in progress - if me.pb.Last == "--gui" { - me.pb.Debugf("DEBUG: last=%s found --gui", me.pb.Last) + if lastarg == "--gui" { + me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real) me.pb.SendString("andlabs gogui") os.Exit(0) } else { - // me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", me.pb.Last, key, val) + // me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", me.last, key, val) } if me.pb.Fast { - if last.Fast { + if me.last.Fast { os.Exit(0) } else { // this means the user is pressing tab. no longer doing stderr - if me.pb.Cmd == "" { + if me.pb.GetCmd() == "" { // me.pp.WriteHelp(os.Stderr) me.writeHelpFunc() } else { // me.pp.WriteHelpForSubcommand(os.Stderr, me.pb.Cmd) - me.writeHelpForSubcommandFunc(me.pb.Cmd) + me.writeHelpForSubcommandFunc(me.pb.GetCmd()) } } } else { @@ -201,7 +202,7 @@ func Autocomplete(dest any) *Argv { } else { me.autoFunc(me.pb) // run the autocomplete function the user made for their application } - if me.pb.Debug { + if me.debug { // TODO: // check here to see if there was any completion text sent // if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user |
