summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-18 06:37:00 -0500
committerJeff Carr <[email protected]>2025-10-18 06:37:00 -0500
commitb2c353f48082a1d581bee0b6ee71c93f58bff603 (patch)
tree1a77d472dda8d720b13e15f4ca39d8645396d5f3
parent8d1a704d6f41b5f08aabc276d1476266f51c5b63 (diff)
pass the flags to the go-arg parser
-rw-r--r--interface.go23
-rw-r--r--structs.go4
-rw-r--r--theMagicOfAutocomplete.go7
3 files changed, 31 insertions, 3 deletions
diff --git a/interface.go b/interface.go
index 72c1b50..13b2e71 100644
--- a/interface.go
+++ b/interface.go
@@ -17,6 +17,12 @@ type mustParseI interface {
MustParse() error
}
+type parseFlagsI interface {
+ // Version returns the version string that will be printed on a line by itself
+ // at the top of the help message.
+ ParseFlags([]string) 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.
@@ -81,6 +87,12 @@ func findAppInfo(tmp interface{}) {
panic("you must define in your app the function: func (args) MustParse() error")
}
+ if tmp, ok := tmp.(parseFlagsI); ok {
+ me.parseFlagsFunc = tmp.ParseFlags
+ } else {
+ parseFlagsHelp()
+ }
+
if tmp, ok := tmp.(initGuiI); ok {
me.initGuiFunc = tmp.InitGui
if err := tmp.InitGui(); err != nil {
@@ -126,3 +138,14 @@ func findAppInfo(tmp interface{}) {
// panic("you need to make the function argv.Exit()")
}
}
+
+func parseFlagsHelp() {
+ log.Info("")
+ log.Info("// this function will send the current argv PB to go-args for parsing")
+ log.Info("func (args) ParseFlags(flags []string) error {")
+ log.Info(" arg.ParseFlags(flags)")
+ log.Info("}")
+ log.Info("")
+
+ panic("you must define in your app the function: func (args) ParseFlags([]string) error")
+}
diff --git a/structs.go b/structs.go
index ab7faa5..4ec64cb 100644
--- a/structs.go
+++ b/structs.go
@@ -10,8 +10,8 @@ type AutoArgs struct {
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
- mustParseFunc func() error // notsure yet
- parseFlags func([]string) error // notsure yet
+ mustParseFunc func() error // calls go-arg.MustParse()
+ parseFlagsFunc func([]string) error // notsure yet
writeHelp func() // notsure yet
writeHelpForSubcommand func(string) // notsure yet
writeHelpForAutocomplete func() // notsure yet
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 8030feb..550b63d 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -130,10 +130,15 @@ func Autocomplete(dest any) *Argv {
// use go-args to parse the structs so we can use them here
// me.pp, err = arg.ParseFlags(flags, dest)
- if err := me.parseFlags(flags); err != nil {
+ if me.parseFlagsFunc == nil {
+ panic("argv.parseFlags() is nil")
+ }
+
+ if err := me.parseFlagsFunc(flags); err != nil {
log.Info("application parseFlags() err", err)
panic("argv.parseFlags() err")
}
+
if len(flags) == 0 {
// error is normal if there are no command line args
} else {