diff options
| author | Jeff Carr <[email protected]> | 2025-10-14 00:16:26 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-14 00:16:26 -0500 |
| commit | 660620c105f1a0a7d5e95ab6e2d4dc10113fd249 (patch) | |
| tree | a3fc7c9a479eb91360be286f1b62b309713a20fb | |
| parent | 38223d25713916ae25261d7adb78c1fa0c40227d (diff) | |
changes for new lib/config function namesv0.0.35
| -rw-r--r-- | exit.go | 2 | ||||
| -rw-r--r-- | interface.go | 3 | ||||
| -rw-r--r-- | structs.go | 7 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 19 |
4 files changed, 22 insertions, 9 deletions
@@ -68,7 +68,7 @@ func ExitWatchdog() { return case t := <-dog.C: _ = t - log.Info("argv.Exit() watchdog: stalled in", myAuto.appName+".Exit()") + log.Info("argv.Exit() watchdog: stalled in", myAuto.ARGNAME+".Exit()") // h.Scan() } } diff --git a/interface.go b/interface.go index 1439ec4..24f61c3 100644 --- a/interface.go +++ b/interface.go @@ -47,13 +47,14 @@ type exitI interface { // Described is the interface that the destination struct should implement to func findAppInfo(tmp interface{}) { if tmp, ok := tmp.(appnameI); ok { - myAuto.appName = tmp.Appname() + myAuto.ARGNAME = tmp.Appname() } else { panic("you must define in your app the function: (argv) func Appname() string") } if tmp, ok := tmp.(buildtimeI); ok { myAuto.buildtime = tmp.Buildtime + myAuto.BUILDTIME, myAuto.VERSION = myAuto.buildtime() } else { // panic("your app is missing (argv) func Buildtime() (string, string)") } @@ -26,7 +26,6 @@ type AutoArgs struct { id int // should be unique hidden bool // don't update the toolkits when it's hidden Auto func([]string) // the function for shell autocomplete - appName string // a good way to track the name of the binary ? examples func() string // some examples appExit func() // app Exit() buildtime func() (string, string) // some examples @@ -34,6 +33,10 @@ type AutoArgs struct { autoFunc func(*Auto) // also a function for autocomplete guiFunc func() error // enables Gui functions err error // store any errors from argv + + ARGNAME string // a good way to track the name of the binary ? + VERSION string + BUILDTIME string } // returns the last command (is blank if the current arg is not blank) @@ -52,5 +55,5 @@ func GetLast(cur string, argv []string) string { // returns the name of the executable registered for shell autocomplete func AppName() string { - return myAuto.appName + return myAuto.ARGNAME } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 89560c5..eadffb6 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -14,6 +14,7 @@ import ( timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) +// TODO: rename 'all' to 'pb' and 'pb' to 'pbnew' or 'pbcur' func Autocomplete(dest any) *Auto { myAuto = new(AutoArgs) // todo: redo this findAppInfo(dest) // parses back to main() for argv info @@ -26,13 +27,21 @@ func Autocomplete(dest any) *Auto { // log.Info("no gui init") } - // load the argv history from the protobuf file + // parses os.Args into a protobuf + pb := parseArgv(myAuto.ARGNAME) + + // the argv history all := NewAutos() - err := config.LoadCache(all, "argv", myAuto.appName) // loads ~/.cache/argv/forge.pb + + // initializes the application config file + config.Init(myAuto.ARGNAME, myAuto.VERSION, myAuto.BUILDTIME, pb.Argv) + + // loads the autocomplete history file + err := config.LoadCache(all, "argv", myAuto.ARGNAME) // if err != nil { - // there is no history. do something here(?) + // there is no history. + // todo: initialize the history file } - pb := parseArgv(myAuto.appName) // parses os.Args into a protobuf // set the start time of the binary now := time.Now() @@ -46,7 +55,7 @@ func Autocomplete(dest any) *Auto { // --bash or --zsh is the first os.Args if pb.SetupAuto { // --bash was passed. try to configure bash-completion - MakeAutocompleteFiles(myAuto.appName) + MakeAutocompleteFiles(myAuto.ARGNAME) // never forget to run this our you will hate yourself and the choices you have made os.Exit(0) } |
