summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-18 05:10:17 -0500
committerJeff Carr <[email protected]>2025-10-18 05:10:17 -0500
commit8d1a704d6f41b5f08aabc276d1476266f51c5b63 (patch)
tree46c6f81796b9ef351976debf2d8fe216fff56962
parent7ef1d9192c366423f5e6bf2b68946aac5cdea336 (diff)
move go-args back to the application code
-rw-r--r--Makefile7
-rw-r--r--argv.Print.go5
-rw-r--r--argv.SendStrings.go11
-rw-r--r--debugger.go42
-rw-r--r--interface.go12
-rw-r--r--structs.go39
-rw-r--r--theMagicOfAutocomplete.go33
7 files changed, 64 insertions, 85 deletions
diff --git a/Makefile b/Makefile
index 2d5b734..656758e 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,13 @@ clean:
-rm -f go.*
go-mod-clean purge
+redomod:
+ rm -f go.*
+ goimports -w *.go
+ GO111MODULE= go mod init
+ GO111MODULE= go mod tidy
+
+
# fixes your numbers if you move things around
# THIS TOTALLY BREAKS THE POINT OF PROTOBUF
# To work around that breaking, you must change the version
diff --git a/argv.Print.go b/argv.Print.go
index d0a4447..68e79d1 100644
--- a/argv.Print.go
+++ b/argv.Print.go
@@ -53,8 +53,3 @@ func (all *Argvs) PrintHistory() {
pb.PrintDebugNew("HIST")
}
}
-
-// todo: fix this
-func (pb *Argv) WriteHelp() {
- me.pp.WriteHelp(os.Stdout)
-}
diff --git a/argv.SendStrings.go b/argv.SendStrings.go
index 827e690..367de07 100644
--- a/argv.SendStrings.go
+++ b/argv.SendStrings.go
@@ -42,7 +42,6 @@ func (pb *Argv) GenerateSubCommandStrings(cmd ...string) {
}
func (pb *Argv) SubCommand(cmd ...string) {
- partial := strings.Trim(pb.Partial, "'")
if pb.Debug {
if me.examples == nil {
pb.Debugf("WRITE DEBUG: argv.Examples() not defined")
@@ -58,13 +57,15 @@ func (pb *Argv) SubCommand(cmd ...string) {
}
// log.Fprintf(os.Stderr, "\n")
}
- me.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...)
+ // last working line: me.writeHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...)
+ me.writeHelpForAutocomplete()
+
// me.pp.GetUsageForSubcommand(os.Stdout, os.Stderr, partial, cmd)
// me.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
} else {
- f, _ := os.OpenFile("/tmp/outlook", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
- me.pp.WriteHelpForAutocomplete(f, os.Stdout, partial, cmd...)
- // me.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
+ // last working: f, _ := os.OpenFile("/tmp/outlook", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+ // last working: me.writeHelpForAutocomplete(f, os.Stdout, partial, cmd...)
+ me.writeHelpForAutocomplete()
}
os.Exit(0)
}
diff --git a/debugger.go b/debugger.go
deleted file mode 100644
index 0fbce7d..0000000
--- a/debugger.go
+++ /dev/null
@@ -1,42 +0,0 @@
-package argvpb
-
-// initializes logging and command line options
-
-import (
- "go.wit.com/dev/alexflint/arg"
- "go.wit.com/log"
-)
-
-var INFO *log.LogFlag
-var POLL *log.LogFlag
-var CHAN *log.LogFlag
-var WARN *log.LogFlag
-
-var argDebugger ArgsDebugger
-
-// This struct can be used with the go-arg package
-type ArgsDebugger struct {
- Debugger bool `arg:"--debugger" help:"open the debugger window"`
- Logger bool `arg:"--logger" help:"open the log.* control window"`
-}
-
-// returns true if --gui-debug was passed from the command line
-func ArgDebug() bool {
- return argDebugger.Debugger
-}
-
-func ArgLogger() bool {
- return argDebugger.Logger
-}
-
-func Debugger() {
- arg.Register(&argDebugger)
-
- full := "go.wit.com/bug/debugger"
- short := "bugger"
-
- INFO = log.NewFlag("INFO", false, full, short, "simple debugging Info()")
- POLL = log.NewFlag("POLL", false, full, short, "watch the debugger poll things")
- CHAN = log.NewFlag("CHAN", true, full, short, "chan() test code output")
- WARN = log.NewFlag("WARN", true, full, short, "should warn the user")
-}
diff --git a/interface.go b/interface.go
index d1d3aec..72c1b50 100644
--- a/interface.go
+++ b/interface.go
@@ -11,6 +11,12 @@ type initArgvI interface {
InitArgv() (string, string, string)
}
+type mustParseI interface {
+ // Version returns the version string that will be printed on a line by itself
+ // at the top of the help message.
+ MustParse() 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.
@@ -69,6 +75,12 @@ func findAppInfo(tmp interface{}) {
panic("you must define in your app the function: (args) func InitArgv() (string, string, string)")
}
+ if tmp, ok := tmp.(mustParseI); ok {
+ me.mustParseFunc = tmp.MustParse
+ } else {
+ panic("you must define in your app the function: func (args) MustParse() error")
+ }
+
if tmp, ok := tmp.(initGuiI); ok {
me.initGuiFunc = tmp.InitGui
if err := tmp.InitGui(); err != nil {
diff --git a/structs.go b/structs.go
index 29083ac..ab7faa5 100644
--- a/structs.go
+++ b/structs.go
@@ -1,28 +1,29 @@
package argvpb
-import (
- "go.wit.com/dev/alexflint/arg"
-)
-
// try this struct out (?)
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
- 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
+ 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
+ initGuiFunc func() error // this is required for 'gui' args to work
+ mustParseFunc func() error // notsure yet
+ parseFlags func([]string) error // notsure yet
+ writeHelp func() // notsure yet
+ writeHelpForSubcommand func(string) // notsure yet
+ writeHelpForAutocomplete func() // notsure yet
+ 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
+ // pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
}
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index f49cd61..8030feb 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -9,8 +9,8 @@ import (
"strings"
"time"
- "go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/config"
+ "go.wit.com/log"
durationpb "google.golang.org/protobuf/types/known/durationpb"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
@@ -50,13 +50,12 @@ func Autocomplete(dest any) *Argv {
me.pb.Ctime = timestamppb.New(now)
// try to register bash args for go-args
- arg.Register(&ArgvBash)
- // arg.Register(&argGui)
+ // arg.Register(&ArgvBash)
// user is trying to setup bash or zsh autocomplete
// --bash or --zsh is the first os.Args
if me.pb.SetupAuto {
- // --bash was passed. try to configure bash-completion
+ // --bash or --zsh was passed. try to configure bash-completion
MakeAutocompleteFiles(me.ARGNAME)
// never forget to run this our you will hate yourself and the choices you have made
os.Exit(0)
@@ -68,8 +67,8 @@ func Autocomplete(dest any) *Argv {
all.Clone(me.pb)
errors.Join(err, all.Save())
- me.pp = arg.MustParse(dest)
- me.err = err
+ // me.pp = arg.MustParse(dest)
+ me.err = me.mustParseFunc()
return me.pb
}
@@ -130,7 +129,11 @@ 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)
+ // me.pp, err = arg.ParseFlags(flags, dest)
+ if err := me.parseFlags(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 {
@@ -140,11 +143,11 @@ func Autocomplete(dest any) *Argv {
}
}
- if me.pp == nil {
- me.pb.Debugf("DEBUG: me.pp == nil after ParseFlags()")
- } else {
- // me.pb.Debugf("DEBUG: me.pp is ok after ParseFlags()")
- }
+ // if me.pp == nil {
+ // me.pb.Debugf("DEBUG: me.pp == nil after ParseFlags()")
+ // } else {
+ // me.pb.Debugf("DEBUG: me.pp is ok after ParseFlags()")
+ // }
// save now. this is near the end probably
all.Clone(me.pb)
@@ -165,9 +168,11 @@ func Autocomplete(dest any) *Argv {
} else {
// this means the user is pressing tab. no longer doing stderr
if me.pb.Cmd == "" {
- me.pp.WriteHelp(os.Stderr)
+ // me.pp.WriteHelp(os.Stderr)
+ me.writeHelp()
} else {
- me.pp.WriteHelpForSubcommand(os.Stderr, me.pb.Cmd)
+ // me.pp.WriteHelpForSubcommand(os.Stderr, me.pb.Cmd)
+ me.writeHelpForSubcommand(me.pb.Cmd)
}
}
} else {