summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-21 15:48:24 -0500
committerJeff Carr <[email protected]>2025-10-21 15:48:24 -0500
commit2b6414a664fd7ccc519874f4d0b55a12a871307c (patch)
treeb72eba5a53e98a219f4a54249241e2fd9b66e6d8 /theMagicOfAutocomplete.go
parente9c3000abafd70702cb9db6e3738115012f498eb (diff)
housecleaning
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go74
1 files changed, 21 insertions, 53 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index e8e4594..9155517 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -17,38 +17,14 @@ import (
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
-// gets APPNAME, BUILDTIME and VERSION from the application
-func initAppname() {
- app := new(App)
- APPNAME, anyString, VERSION := me.initArgvFunc()
- app.APPNAME = APPNAME
- app.VERSION = VERSION
- //
- // this logic isn't great, but it's what it is right now
- //
- // the reason this logic is messy is because cobol is supposed to "guess"
- // that is the point of the cobol package and I've been using this code here
- // to test the guesses because it's an easy place to test that code
- //
- if BUILDTIME, err := cobol.GetTime(anyString); BUILDTIME != nil {
- // everyhting is working. BUILDTIME is *time.Time
- app.BUILDTIME = cobol.Time(BUILDTIME)
- } else if err == nil {
- newtime := BUILDTIME.Add(-36 * time.Hour)
- app.BUILDTIME = cobol.Time(BUILDTIME)
- log.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, newtime, app.BUILDTIME)
- } else {
- app.BUILDTIME = anyString
- log.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, BUILDTIME, app.BUILDTIME)
- }
- me.pb.AppInfo = app
- me.pb.Argname = APPNAME // deprecate this
-}
-
func Autocomplete(dest any) *Argv {
me = new(AutoArgs) // todo: redo this
me.pb = new(Argv)
+ // set the start time of the binary
+ now := time.Now()
+ me.pb.Ctime = timestamppb.New(now)
+
// makes sure the application has the
// needed functions defined, otherwise panics
verifyApplication(dest)
@@ -56,25 +32,14 @@ func Autocomplete(dest any) *Argv {
// gets APPNAME, BUILDTIME and VERSION from the application
initAppname()
- // parses os.Args into a protobuf
+ // parses os.Args into the protobuf
me.pb.parseArgv()
- // todo: figure this out
- if me.guiFunc != nil {
- // register gui args
- me.guiFunc()
- // log.Info("gui init")
- } else {
- // log.Info("no gui init")
- }
-
- // the argv history
- all := NewArgvs()
-
- // initializes the application config file
+ // 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)
- // loads the autocomplete history file
+ // loads the argv autocomplete history file
+ all := NewArgvs()
err := config.LoadCache(all, "argv", me.pb.AppInfo.APPNAME) //
if err != nil {
// there is no history.
@@ -82,12 +47,16 @@ func Autocomplete(dest any) *Argv {
// todo: check if this is automatically done already
}
- // set the start time of the binary
- now := time.Now()
- me.pb.Ctime = timestamppb.New(now)
-
// try to register bash args for go-args
// arg.Register(&ArgvBash)
+ // todo: figure this out
+ if me.guiFunc != nil {
+ // register gui args
+ me.guiFunc()
+ // log.Info("gui init")
+ } else {
+ // log.Info("no gui init")
+ }
// user is trying to setup bash or zsh autocomplete
// --bash or --zsh is the first os.Args
@@ -163,6 +132,11 @@ func Autocomplete(dest any) *Argv {
flags = append(flags, s)
}
+ if strings.HasPrefix(me.pb.Last, "--argv") {
+ me.pb.SendString("--argvdebug --argvhelp")
+ os.Exit(0)
+ }
+
// use go-args to parse the structs so we can use them here
// me.pp, err = arg.ParseFlags(flags, dest)
if me.parseFlagsFunc == nil {
@@ -183,12 +157,6 @@ func Autocomplete(dest any) *Argv {
}
}
- // if me.pp == nil {
- // me.pb.Debugf("DEBUG: me.pp == nil after ParseFlags()")
- // } else {
- // me.pb.Debugf("DEBUG: me.pp is ok after ParseFlags()")
- // }
-
// save now. this is near the end probably
all.Clone(me.pb)
errors.Join(err, all.Save())