diff options
| -rw-r--r-- | interface.go | 47 | ||||
| -rw-r--r-- | notsure.go | 2 | ||||
| -rw-r--r-- | structs.go | 28 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 2 |
4 files changed, 54 insertions, 25 deletions
diff --git a/interface.go b/interface.go index 02541a6..d1d3aec 100644 --- a/interface.go +++ b/interface.go @@ -1,9 +1,25 @@ package argvpb +import "go.wit.com/log" + // this is a work in progress -// Versioned is the interface that the destination struct should implement to -// make a version string appear at the top of the help message. +// WORKING ON START +type initArgvI interface { + // Version returns the version string that will be printed on a line by itself + // at the top of the help message. + InitArgv() (string, string, string) +} + +type initGuiI interface { + // Version returns the version string that will be printed on a line by itself + // at the top of the help message. + InitGui() error +} + +// WORKING ON END + +// NOTSURE ABOUT START type appnameI interface { // Version returns the version string that will be printed on a line by itself // at the top of the help message. @@ -46,10 +62,28 @@ type exitI interface { // Described is the interface that the destination struct should implement to func findAppInfo(tmp interface{}) { + // THIS STUFF IS FINALIZED FOR NOW 2025/10/18 (review in a few months) + if tmp, ok := tmp.(initArgvI); ok { + me.ARGNAME, me.BUILDTIME, me.VERSION = tmp.InitArgv() + } else { + panic("you must define in your app the function: (args) func InitArgv() (string, string, string)") + } + + if tmp, ok := tmp.(initGuiI); ok { + me.initGuiFunc = tmp.InitGui + if err := tmp.InitGui(); err != nil { + log.Info("go.wit.com/gui failed to initialize", err) + panic("gui failed to init") + } + } else { + panic("you must add this function to argv.go: (argv) func InitGui() error") + } + + // TODO: SORT OUT STUFF BELOW HERE if tmp, ok := tmp.(appnameI); ok { me.ARGNAME = tmp.Appname() } else { - panic("you must define in your app the function: (argv) func Appname() string") + // panic("you must define in your app the function: (argv) func Appname() string") } if tmp, ok := tmp.(buildtimeI); ok { @@ -62,13 +96,6 @@ func findAppInfo(tmp interface{}) { if tmp, ok := tmp.(examplesI); ok { me.examples = tmp.Examples } - - if tmp, ok := tmp.(guiI); ok { - me.guiFunc = tmp.ArgvGui - } else { - // panic("you must add this function to argv.go: (argv) func ArgvGui() error") - } - if tmp, ok := tmp.(autoFuncI); ok { me.autoFunc = tmp.DoAutoComplete } else { @@ -6,7 +6,7 @@ package argvpb // this is sill in development // figure out how to trigger this -var argBash ArgsBash +var ArgvBash ArgsBash type ArgsBash struct { Bash bool `arg:"--bash" help:"generate bash completion"` @@ -9,18 +9,20 @@ var me *AutoArgs // this is a work in progress type AutoArgs struct { - pb *Argv // the protobuf for the current process - pp *arg.Parser // for parsing the command line args. Yay to alexf lint! - id int // should be unique - Argv func([]string) // the function for shell autocomplete - examples func() string // some examples - appExit func() // app Exit() - buildtime func() (string, string) // some examples - autoFunc func(*Argv) // also a function for autocomplete - guiFunc func() error // enables Gui functions - ARGNAME string // a good way to track the name of the binary ? - VERSION string - BUILDTIME string - err error // store any errors from argv + pb *Argv // the protobuf for the current process + pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + id int // should be unique + Argv func([]string) // the function for shell autocomplete + initArgv func() (string, string, string) // this is required. gets APPNAME, BUILDTIME & VERSION + initGuiFunc func() error // this is required for 'gui' args to work + examples func() string // some examples + appExit func() // app Exit() + buildtime func() (string, string) // some examples + autoFunc func(*Argv) // also a function for autocomplete + guiFunc func() error // enables Gui functions + ARGNAME string // a good way to track the name of the binary ? + VERSION string + BUILDTIME string + err error // store any errors from argv // hidden bool // don't update the toolkits when it's hidden } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index a5516d2..f49cd61 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -50,7 +50,7 @@ func Autocomplete(dest any) *Argv { me.pb.Ctime = timestamppb.New(now) // try to register bash args for go-args - arg.Register(&argBash) + arg.Register(&ArgvBash) // arg.Register(&argGui) // user is trying to setup bash or zsh autocomplete |
