diff options
| author | Jeff Carr <[email protected]> | 2025-10-26 08:31:13 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-26 08:31:13 -0500 |
| commit | 042fac23113c134b3615939b0836263fd12b3bd1 (patch) | |
| tree | b46492b135af76e0e045e887c6a5ea941516c490 | |
| parent | cfee0dad2418f8e800d15edd3e6b32cebd1119dc (diff) | |
new argv Init()
| -rw-r--r-- | exit.go | 8 | ||||
| -rw-r--r-- | init.go | 24 | ||||
| -rw-r--r-- | makeAutocompleteFiles.bash.go | 10 | ||||
| -rw-r--r-- | structs.go | 5 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 26 | ||||
| -rw-r--r-- | verifyApplication.go | 2 |
6 files changed, 32 insertions, 43 deletions
@@ -15,14 +15,14 @@ import ( // also, it supports a custom Exit() back to your application func GoodExit(msg string) { - me.pb.GoodExit(msg) + PB.goodExit(msg) } func BadExit(msg string, err error) { - me.pb.BadExit(msg, err) + PB.badExit(msg, err) } -func (pb *Argv) GoodExit(msg string) { +func (pb *Argv) goodExit(msg string) { go ExitWatchdog() if me.appExit != nil { me.appExit() @@ -38,7 +38,7 @@ func (pb *Argv) GoodExit(msg string) { os.Exit(0) } -func (pb *Argv) BadExit(msg string, err error) { +func (pb *Argv) badExit(msg string, err error) { go ExitWatchdog() if me.appExit != nil { me.appExit() @@ -4,13 +4,17 @@ import ( "fmt" "time" + "github.com/google/uuid" "go.wit.com/lib/cobol" + timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) -// gets APPNAME, BUILDTIME and VERSION from the application -func initAppname() { +func Init(dest any, APPNAME string, anyString string, VERSION string) { + me = new(AutoType) + me.pb = new(Argv) + PB = me.pb + app := new(App) - APPNAME, anyString, VERSION := me.initArgvFunc() app.APPNAME = APPNAME app.VERSION = VERSION // @@ -32,4 +36,18 @@ func initAppname() { fmt.Printf("TIME initAppname() ERR=(%v) anyString=(%v) GetTime.BUILTIME=(%v) app.BUILDTIME=(%v)\n", err, anyString, BUILDTIME, app.BUILDTIME) } me.pb.AppInfo = app + + fakeStdout() + me.pb.Uuid = uuid.New().String() + + // set the start time of the binary + now := time.Now() + me.pb.Ctime = timestamppb.New(now) + + // makes sure the application has the + // needed functions defined, otherwise dies + verifyApplication(dest) + + // do autocomplete + Autocomplete() } diff --git a/makeAutocompleteFiles.bash.go b/makeAutocompleteFiles.bash.go index 45be925..ed391f2 100644 --- a/makeAutocompleteFiles.bash.go +++ b/makeAutocompleteFiles.bash.go @@ -37,16 +37,6 @@ func MakeBashCompleteFiles(argname string) { } } -// deprecate this -func Bash3(dest any) *Argv { - return Autocomplete(dest) -} - -// deprecate this -func Bash(dest any) *Argv { - return Autocomplete(dest) -} - func makeCompletionText(argname string) string { sh := getParentProcessName() return fmt.Sprintf("# shell might be %s", sh) @@ -1,12 +1,13 @@ package argvpb // try this struct out (?) -var me *AutoArgs +var me *AutoType +// try a global here to see how that turns out var PB *Argv // this is a work in progress -type AutoArgs struct { +type AutoType struct { pb *Argv // the protobuf for the current process all *Argvs // the history of argv last *Argv // the pb from the last time the user tried autocomplete diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index fd75cf6..f67f9ff 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -10,36 +10,17 @@ import ( "strings" "time" - "github.com/google/uuid" "go.wit.com/lib/cobol" "go.wit.com/lib/config" "go.wit.com/lib/env" durationpb "google.golang.org/protobuf/types/known/durationpb" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) // This function behaves oddly. It works in several different ways. It can: // - Initialize a protobuf and returns it to the application // - Help a user generate shell completion support & os.Exit // - figures out what to print to Stdout & Stderr and then does os.Exit() -func Autocomplete(dest any) *Argv { - me = new(AutoArgs) // todo: redo this - me.pb = new(Argv) - PB = me.pb - fakeStdout() - me.pb.Uuid = uuid.New().String() - - // set the start time of the binary - now := time.Now() - me.pb.Ctime = timestamppb.New(now) - - // makes sure the application has the - // needed functions defined, otherwise dies - verifyApplication(dest) - - // gets APPNAME, BUILDTIME and VERSION from the application - initAppname() - +func Autocomplete() *Argv { // parses os.Args into the protobuf me.pb.parseOsArgs() @@ -238,10 +219,9 @@ func examineArgvHistory() { // only have nil values in the .pb file. just die for now if me.all.Len() == 0 { me.debug = true - me.pb.Stderr += fmt.Sprintf("examineArgvHistory() couldn't find a valid last entry") + fmt.Fprintf(Stderr, "examineArgvHistory() empty file %s\n", me.all.Filename) doStdoutStderr() - // todo: make a blank entry here - panic("examineArgvHistory() couldn't find a valid last entry") + saveAndExit() } // finally safe to get the last history entry diff --git a/verifyApplication.go b/verifyApplication.go index f38bec7..18e61d7 100644 --- a/verifyApplication.go +++ b/verifyApplication.go @@ -8,7 +8,7 @@ func verifyApplication(tmp interface{}) { if tmp, ok := tmp.(initArgvI); ok { me.initArgvFunc = tmp.InitArgv } else { - panic("you must define in your app the function: (args) func InitArgv() (string, string, string)") + // panic("you must define in your app the function: (args) func InitArgv() (string, string, string)") } if tmp, ok := tmp.(mustParseI); ok { |
