summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-14 00:16:26 -0500
committerJeff Carr <[email protected]>2025-10-14 00:16:26 -0500
commit660620c105f1a0a7d5e95ab6e2d4dc10113fd249 (patch)
treea3fc7c9a479eb91360be286f1b62b309713a20fb
parent38223d25713916ae25261d7adb78c1fa0c40227d (diff)
changes for new lib/config function namesv0.0.35
-rw-r--r--exit.go2
-rw-r--r--interface.go3
-rw-r--r--structs.go7
-rw-r--r--theMagicOfAutocomplete.go19
4 files changed, 22 insertions, 9 deletions
diff --git a/exit.go b/exit.go
index f53c1b6..a9deec7 100644
--- a/exit.go
+++ b/exit.go
@@ -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)")
}
diff --git a/structs.go b/structs.go
index 01a6f56..052c7ad 100644
--- a/structs.go
+++ b/structs.go
@@ -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)
}