still tuning the autocomplete code

This commit is contained in:
Jeff Carr 2025-09-18 16:03:40 -05:00
parent e0c508f197
commit 87751f7c72
1 changed files with 25 additions and 15 deletions

View File

@ -253,21 +253,17 @@ func parseArgv(argname string) *Auto {
newauto.Cmd = s
break
}
if newauto.Cmd == "" {
newauto.Cmd = strings.Join(newauto.Argv, "BLAH")
if newauto.Partial == "'"+newauto.Cmd+"'" {
// not really a command, it's just a partially inputed string from the user
newauto.Cmd = ""
}
return newauto
// if newauto.Cmd == "" {
// newauto.Cmd = strings.Join(newauto.Argv, "BLAH")
// }
}
return newauto
}
// MustParse processes command line arguments and exits upon failure
func MustParse(dest ...interface{}) *arg.Parser {
// arg.
// register = append(register, dest...)
return arg.MustParse(dest)
}
// also try to parse/send cur (?)
func Bash2(argname string, appAutoFunc func(*Auto)) *Auto {
pb := parseArgv(argname)
@ -320,12 +316,14 @@ func Bash3(argname string, appAutoFunc func(*Auto), dest any) *Auto {
}
if pb.IsAuto {
pb.doHandlePB()
if pb.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
pb.doHandlePB() // read in the history protobuf file
// turn on debugging if duration < 200 milliseconds
dur := pb.Duration.AsDuration()
if dur < time.Millisecond*200 {
pb.Debug = true
}
arg.Register(&argBash)
flags := []string{}
for _, s := range pb.Argv {
@ -334,6 +332,7 @@ func Bash3(argname string, appAutoFunc func(*Auto), dest any) *Auto {
}
flags = append(flags, s)
}
// pb.Debug = true
pb.Debugf("DEBUG: MustParse(%v)", flags)
var err error
myAuto.pp, err = arg.ParseFlags(flags, dest)
@ -341,7 +340,18 @@ func Bash3(argname string, appAutoFunc func(*Auto), dest any) *Auto {
pb.Debugf("DEBUG: Parse error: %v", err)
}
if myAuto.pp == nil {
pb.Debugf("DEBUG: myAuto.pp == nil after ParseFlags()")
} else {
pb.Debugf("DEBUG: myAuto.pp is ok after ParseFlags()")
}
appAutoFunc(pb) // run the autocomplete function the user made for their application
if pb.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
}
os.Exit(0)
}