diff options
| author | Jeff Carr <[email protected]> | 2025-10-19 11:41:24 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-19 11:41:24 -0500 |
| commit | 8c44dd2eb48319b3511982e78dc6ef06b43ea3ac (patch) | |
| tree | dc5d0a2341378a0b02a739273cf364516dd089b4 | |
| parent | 478735e1a7053ccab711a918b7db13ac59081827 (diff) | |
further cleanup order of theMagic()
| -rw-r--r-- | argv.parseOsArgs.go (renamed from parseOsArgs.go) | 19 | ||||
| -rw-r--r-- | structs.go | 2 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 27 | ||||
| -rw-r--r-- | verifyApplication.go (renamed from interface.go) | 183 |
4 files changed, 116 insertions, 115 deletions
diff --git a/parseOsArgs.go b/argv.parseOsArgs.go index 4959944..eb6f7d6 100644 --- a/parseOsArgs.go +++ b/argv.parseOsArgs.go @@ -10,32 +10,29 @@ import ( "go.wit.com/log" ) -func parseArgv(argname string) *Argv { - pb := new(Argv) - pb.Argname = argname - +func (pb *Argv) parseArgv() { // this shouldn't really happen. OS/POSIX error? if len(os.Args) == 0 { // fmt.Fprintf(os.Stderr, "what OS is this?\n") - return pb + return } // there is nothing on the command line. user just ran "forge" and hit enter if len(os.Args) == 1 { pb.Arg0 = os.Args[0] - return pb + return } // try to setup bash autocomplete and exit if len(os.Args) > 1 && os.Args[1] == "--bash" { pb.SetupAuto = true - return pb + return } // try to setup zsh autocomplete and exit if len(os.Args) > 1 && os.Args[1] == "--zsh" { pb.SetupAuto = true - return pb + return } // set debug flag if --argvdebug is passed @@ -85,7 +82,7 @@ func parseArgv(argname string) *Argv { } // exit here. not autocomplete // todo: actually finish parsing the pb. is it safe to continue from here? - return pb + return } // should we do auto complete here? @@ -100,7 +97,7 @@ func parseArgv(argname string) *Argv { pb.Partial = "" pb.Cmd = "" pb.Real = []string{""} - return pb + return } if pb.Partial == "''" { pb.Partial = "" @@ -149,5 +146,5 @@ func parseArgv(argname string) *Argv { // pb.Cmd = strings.Join(pb.Argv, "BLAH") // } } - return pb + return } @@ -10,7 +10,7 @@ type AutoArgs struct { pb *Argv // the protobuf for the current process 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 + initArgvFunc func() (string, string, string) // this is required. gets APPNAME, BUILDTIME & VERSION initGuiFunc func() error // this is required for 'gui' args to work mustParseFunc func() error // calls go-arg.MustParse() parseFlagsFunc func([]string) error // calls go-arg.ParseFlags(flags) diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index a4137d6..ee20b24 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -16,9 +16,31 @@ import ( timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) +// gets APPNAME, BUILDTIME and VERSION from the application +func initAppname() { + ARGNAME, anyString, VERSION := me.initArgvFunc() + me.ARGNAME = ARGNAME + me.VERSION = VERSION + var err error + me.BUILDTIME, err = cobol.GetTime(anyString) + if err != nil { + log.Printf("TIME ERR=(%v) time=(%v) BUILTIME=(%v)\n", err, anyString, me.BUILDTIME) + } +} + func Autocomplete(dest any) *Argv { me = new(AutoArgs) // todo: redo this - findAppInfo(dest) // parses back to main() for argv info + me.pb = new(Argv) + + // makes sure the application has the + // needed functions defined, otherwise panics + verifyApplication(dest) + + // gets APPNAME, BUILDTIME and VERSION from the application + initAppname() + + // parses os.Args into a protobuf + me.pb.parseArgv() // todo: figure this out if me.guiFunc != nil { @@ -29,9 +51,6 @@ func Autocomplete(dest any) *Argv { // log.Info("no gui init") } - // parses os.Args into a protobuf - me.pb = parseArgv(me.ARGNAME) - // the argv history all := NewArgvs() diff --git a/interface.go b/verifyApplication.go index ad343d3..dba5b65 100644 --- a/interface.go +++ b/verifyApplication.go @@ -1,100 +1,14 @@ package argvpb import ( - "go.wit.com/lib/cobol" "go.wit.com/log" ) -// this is a work in progress - -// WORKING ON START - -type initArgvI interface { - InitArgv() (string, string, string) -} - -type mustParseI interface { - MustParse() error -} - -type parseFlagsI interface { - ParseFlags([]string) error -} - -type writeHelpForAutocompleteI interface { - WriteHelpForAutocomplete(string, ...string) error -} - -type writeHelpForAutocompleteDebugI interface { - WriteHelpForAutocompleteDebug(string, ...string) error -} - -type writeHelpForSubcommandI interface { - WriteHelpForSubcommand(cmd string) error -} - -type writeHelpI interface { - WriteHelp() error -} - -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. - Appname() string -} - -// deprecate -type autoFuncI interface { - // Version returns the version string that will be printed on a line by itself - // at the top of the help message. - DoAutoComplete(*Argv) -} - -type sendCompletionStringsI interface { - // Version returns the version string that will be printed on a line by itself - // at the top of the help message. - SendCompletionStrings(*Argv) -} - -type buildtimeI interface { - Buildtime() (string, string) -} - -type examplesI interface { - // Version returns the version string that will be printed on a line by itself - // at the top of the help message. - Examples() string -} - -type guiI interface { - // Version returns the version string that will be printed on a line by itself - // at the top of the help message. - ArgvGui() error -} - -type exitI interface { - // allows a custom app Exit() - Exit() -} - -// 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) +// verify the application has the needed function calls defined +func verifyApplication(tmp interface{}) { + // START NEEDED FUNCS // 2025/10/18 (review in a few months) if tmp, ok := tmp.(initArgvI); ok { - var anyTime string - var err error - me.ARGNAME, anyTime, me.VERSION = tmp.InitArgv() - me.BUILDTIME, err = cobol.GetTime(anyTime) - _ = err + me.initArgvFunc = tmp.InitArgv } else { panic("you must define in your app the function: (args) func InitArgv() (string, string, string)") } @@ -144,6 +58,7 @@ func findAppInfo(tmp interface{}) { } else { // panic("you must add this function to argv.go: (argv) func InitGui() error") } + // END NEEDED FUNCS // 2025/10/18 (review in a few months) // TODO: SORT OUT STUFF BELOW HERE if tmp, ok := tmp.(appnameI); ok { @@ -152,15 +67,6 @@ func findAppInfo(tmp interface{}) { // panic("you must define in your app the function: (argv) func Appname() string") } - /* - if tmp, ok := tmp.(buildtimeI); ok { - me.buildtime = tmp.Buildtime - me.BUILDTIME, me.VERSION = me.buildtime() - } else { - // panic("your app is missing (argv) func Buildtime() (string, string)") - } - */ - if tmp, ok := tmp.(examplesI); ok { me.examples = tmp.Examples } @@ -183,6 +89,85 @@ func findAppInfo(tmp interface{}) { } } +// WORKING ON START + +type initArgvI interface { + InitArgv() (string, string, string) +} + +type mustParseI interface { + MustParse() error +} + +type parseFlagsI interface { + ParseFlags([]string) error +} + +type writeHelpForAutocompleteI interface { + WriteHelpForAutocomplete(string, ...string) error +} + +type writeHelpForAutocompleteDebugI interface { + WriteHelpForAutocompleteDebug(string, ...string) error +} + +type writeHelpForSubcommandI interface { + WriteHelpForSubcommand(cmd string) error +} + +type writeHelpI interface { + WriteHelp() error +} + +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. + Appname() string +} + +// deprecate +type autoFuncI interface { + // Version returns the version string that will be printed on a line by itself + // at the top of the help message. + DoAutoComplete(*Argv) +} + +type sendCompletionStringsI interface { + // Version returns the version string that will be printed on a line by itself + // at the top of the help message. + SendCompletionStrings(*Argv) +} + +type buildtimeI interface { + Buildtime() (string, string) +} + +type examplesI interface { + // Version returns the version string that will be printed on a line by itself + // at the top of the help message. + Examples() string +} + +type guiI interface { + // Version returns the version string that will be printed on a line by itself + // at the top of the help message. + ArgvGui() error +} + +type exitI interface { + // allows a custom app Exit() + Exit() +} + func helpWriteHelpForSubcommand() { log.Info("") log.Info("// add this funcgion: this will print the help") |
