diff options
| -rw-r--r-- | argv.Exit.go | 2 | ||||
| -rw-r--r-- | argv.Version.go | 27 | ||||
| -rw-r--r-- | argv.proto | 2 | ||||
| -rw-r--r-- | notsure.go | 5 | ||||
| -rw-r--r-- | structs.go | 9 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 35 | ||||
| -rw-r--r-- | verifyApplication.go | 6 |
7 files changed, 46 insertions, 40 deletions
diff --git a/argv.Exit.go b/argv.Exit.go index 1419ae2..bbf5c70 100644 --- a/argv.Exit.go +++ b/argv.Exit.go @@ -68,7 +68,7 @@ func ExitWatchdog() { return case t := <-dog.C: _ = t - log.Info("argv.Exit() watchdog: stalled in", me.ARGNAME+".Exit()") + log.Info("argv.Exit() watchdog: stalled in", me.pb.AppInfo.APPNAME+".Exit()") // h.Scan() } } diff --git a/argv.Version.go b/argv.Version.go index 0318c62..c50c52a 100644 --- a/argv.Version.go +++ b/argv.Version.go @@ -10,28 +10,37 @@ import ( "go.wit.com/log" ) +// returns the name of the executable registered for shell autocomplete +func GetAPPNAME() string { + return me.pb.AppInfo.APPNAME +} + func (pb *Argv) Version() string { - return pb.getVersion() + return pb.AppInfo.getVersion() } func doVersion(pb *Argv) { - log.Info(pb.getVersion()) + log.Info(pb.AppInfo.getVersion()) os.Exit(0) } -func (pb *Argv) getVersion() string { +func (info *App) getVersion() string { var s string - timeString, _, err := cobol.TimeCheck(me.BUILDTIME) - if err == nil { - s = fmt.Sprintf("%s %s Built on %s (argv.got(%s))", me.ARGNAME, me.VERSION, timeString, me.BUILDTIME) + timeString, t, err := cobol.TimeCheck(info.BUILDTIME) + if t != nil { + // log.Printf("TIME getVersion(t != nil) ERR=(%v) t=(%v) AppInfo.BUILTIME is=(%v)\n", err, t, info.BUILDTIME) + return fmt.Sprintf("%s %s Built on %s", info.APPNAME, info.VERSION, cobol.Time(t)) + } else if err == nil { + s = fmt.Sprintf("%s %s Built on %s (argv.had(%s))", info.APPNAME, info.VERSION, timeString, info.BUILDTIME) } else { - s = fmt.Sprintf("%s %s Built on raw(%v) %s (from argv)", me.ARGNAME, me.VERSION, me.BUILDTIME, "argv.time.err") + log.Printf("TIME getVersion() ERR=(%v) timeString=(%v) AppInfo.BUILTIME was=(%v)\n", err, timeString, info.BUILDTIME) + s = fmt.Sprintf("%s %s Built on raw(%v) (argv had %s)", info.APPNAME, info.VERSION, timeString, info.BUILDTIME) } return s } /* -func StandardVersion(ARGNAME, VERSION, BUILDTIME string) string { - return fmt.Sprintf("%s %s Built on raw(%v) %s (from argv)", ARGNAME, VERSION, BUILDTIME, cobol.Time(BUILDTIME)) +func StandardVersion(APPNAME, VERSION, BUILDTIME string) string { + return fmt.Sprintf("%s %s Built on raw(%v) %s (from argv)", APPNAME, VERSION, BUILDTIME, cobol.Time(BUILDTIME)) } */ @@ -31,7 +31,7 @@ message Argv { // `autogenpb:marshal` ` repeated string goargs = 15; // what to send to alex flint's go-args for help bool fast = 16; // was the user fast last time? string fastcmd = 17; // what subcommand was the user fast on? - App app = 18; + App appInfo = 18; } message Argvs { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:nomutex` @@ -14,11 +14,6 @@ type ArgsBash struct { Bash bool `arg:"--bash" help:"generate bash completion"` } -// returns the name of the executable registered for shell autocomplete -func AppName() string { - return me.ARGNAME -} - // maybe this is a good idea, maybe not func (pb *Argv) Verbose() bool { return true @@ -1,7 +1,5 @@ package argvpb -import "time" - // try this struct out (?) var me *AutoArgs @@ -23,10 +21,5 @@ type AutoArgs struct { 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 *time.Time - err error // store any errors from argv - // hidden bool // don't update the toolkits when it's hidden - // pp *arg.Parser // for parsing the command line args. Yay to alexf lint! + err error // store any errors from argv } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index ee20b24..bcae20d 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -18,14 +18,29 @@ import ( // 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) + 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 } func Autocomplete(dest any) *Argv { @@ -55,10 +70,10 @@ func Autocomplete(dest any) *Argv { all := NewArgvs() // initializes the application config file - config.Init(me.ARGNAME, me.VERSION, cobol.Time(me.BUILDTIME), me.pb.Real) + config.Init(me.pb.AppInfo.APPNAME, me.pb.AppInfo.VERSION, cobol.Time(me.pb.AppInfo.BUILDTIME), me.pb.Real) // loads the autocomplete history file - err := config.LoadCache(all, "argv", me.ARGNAME) // + err := config.LoadCache(all, "argv", me.pb.AppInfo.APPNAME) // if err != nil { // there is no history. // todo: initialize the history file @@ -76,7 +91,7 @@ func Autocomplete(dest any) *Argv { // --bash or --zsh is the first os.Args if me.pb.SetupAuto { // --bash or --zsh was passed. try to configure bash-completion - MakeAutocompleteFiles(me.ARGNAME) + MakeAutocompleteFiles(me.pb.AppInfo.APPNAME) // never forget to run this our you will hate yourself and the choices you have made os.Exit(0) } diff --git a/verifyApplication.go b/verifyApplication.go index dba5b65..f228dcd 100644 --- a/verifyApplication.go +++ b/verifyApplication.go @@ -61,12 +61,6 @@ func verifyApplication(tmp interface{}) { // END NEEDED FUNCS // 2025/10/18 (review in a few months) // 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") - } - if tmp, ok := tmp.(examplesI); ok { me.examples = tmp.Examples } |
