summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 5b5370b..571c280 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -44,12 +44,25 @@ func Autocomplete(dest any) *Argv {
// loads the argv autocomplete history file
me.all = NewArgvs()
- fullname := config.MakeCacheFilename("argv", me.pb.AppInfo.APPNAME)
- me.Err = config.LoadFromFilename(me.all, fullname)
- if me.Err != nil {
+ me.Err = config.CreateCacheDirPB(me.all, "argv", me.pb.AppInfo.APPNAME)
+ if me.Err == nil {
+ me.all.PrintHistory()
+ } else {
// there is no history.
// todo: initialize the history file
// todo: check if this is automatically done already
+ //
+ // ALWAYS KEEP THESE LINES AND THE panic()
+ //
+ // They are needed to debug autocomplete.
+ //
+ // This code is only executed when the user is hitting tab in the shell,
+ // so this panic() is safe and can never be triggered by normal program execution.
+ //
+ me.debug = true
+ me.pb.Stderr += fmt.Sprintf("config.CreateCacheDirPB() err(%v)\n", me.Err)
+ me.pb.PrintStderr()
+ panic("argvpb.Load() history file failed")
}
// try to register bash args for go-args
@@ -143,6 +156,10 @@ func doAutocomplete() {
if s == "--autodebug" {
continue
}
+ if s == "--argvdebug" {
+ me.pb.PrintStderr()
+ continue
+ }
if strings.TrimSpace(s) == "" {
// skip anything blank
continue
@@ -195,14 +212,14 @@ func doAutocomplete() {
}
}
- // save now. this is near the end probably
- me.all.Clone(me.pb)
- errors.Join(me.Err, me.all.Save())
-
+ me.pb.HelpCounter = me.last.HelpCounter
if me.pb.Fast {
if me.last.Fast {
me.debug = true
- me.pb.PrintStderr()
+ me.pb.HelpCounter = me.last.HelpCounter + 1
+ if me.pb.HelpCounter < 3 {
+ me.pb.PrintStderr()
+ }
} else {
// this means the user is pressing tab. no longer doing stderr
if me.pb.GetCmd() == "" {
@@ -212,10 +229,15 @@ func doAutocomplete() {
// me.pp.WriteHelpForSubcommand(Stderr, me.pb.Cmd)
me.writeHelpForSubcommandFunc(me.pb.GetCmd())
}
+ me.pb.HelpCounter = 0
}
} else {
}
+ // save now. this is near the end probably
+ me.all.Clone(me.pb)
+ errors.Join(me.Err, me.all.Save())
+
if me.autoFunc == nil {
me.pb.SubCommand(me.pb.Real...)
} else {