summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-13 09:53:15 -0500
committerJeff Carr <[email protected]>2025-10-13 09:53:15 -0500
commitd4b928f7bb8f66afc31a95fa4552b8fd8fba3712 (patch)
tree689a40f652bd2f784eb1e028340282bdb2f5739b
parent915ea4f648f8639cb1fc4111fa49ff298ea79441 (diff)
calls back to the apps' main/argv.go but what next?
-rw-r--r--exit.go15
-rw-r--r--gui.go42
-rw-r--r--interface.go14
-rw-r--r--structs.go1
-rw-r--r--theMagicOfAutocomplete.go10
5 files changed, 39 insertions, 43 deletions
diff --git a/exit.go b/exit.go
index 5d629e3..f53c1b6 100644
--- a/exit.go
+++ b/exit.go
@@ -30,11 +30,22 @@ func (pb *Auto) BadExit(msg string, err error) {
if myAuto.appExit != nil {
myAuto.appExit()
}
+ // print out errors. this handles wrapped errors which is a useful
if err != nil {
- log.Info(err)
+ if u, ok := err.(interface{ Unwrap() []error }); ok {
+ // If it does, call the method to get the slice of errors.
+ allerr := u.Unwrap()
+ for _, e := range allerr {
+ log.Info("Error:", e)
+ }
+ } else {
+ // If it's not a joined error, you can fall back to the single-unwrap loop.
+ log.Info("Error:", err)
+ }
}
+
dur := time.Since(pb.Ctime.AsTime())
- log.Infof("%s: %s (%s)\n", pb.Argname, msg, cobol.FormatDuration(dur))
+ log.Infof("%s error: %s (%s)\n", pb.Argname, msg, cobol.FormatDuration(dur))
os.Exit(-1)
}
diff --git a/gui.go b/gui.go
index 8ea20d7..eed96d2 100644
--- a/gui.go
+++ b/gui.go
@@ -2,50 +2,17 @@ package prep
// initializes logging and command line options
-import (
- "os"
-
- "go.wit.com/dev/alexflint/arg"
- "go.wit.com/gui"
- "go.wit.com/lib/fhelp"
- "go.wit.com/log"
-)
-
+/*
var argGui ArgsGui
-/*
-This struct can be used with the go-arg package. These
-are the generic default command line arguments for the 'GUI' package
-*/
+
+// This struct can be used with the go-arg package. These
+// are the generic default command line arguments for the 'GUI' package
type ArgsGui struct {
GuiPlugin string `arg:"--gui" help:"select the plugin (andlabs,gocui,etc)"`
GuiVerbose bool `arg:"--gui-verbose" help:"enable all logging"`
}
-/*
-used for command line options.
-This allows you to control the toolkit settings from the command line
-
- --debugger # opens the debugger
- --gui andlabs # loads the GTK toolkit on linux or Cocoa on mac
- --gui gocui # runs your program in the terminal in ncurses-like mode
-*/
-/*
-func ArgToolkit() string {
- return argGui.GuiPlugin
-}
-
- func init() {
- arg.Register(&argGui)
- }
-
- // this should never happen because this is before go-args MustParse()
- if argGui.GuiPluginHack != "" {
- // does os.Exec() and does not return
- gui.TestPluginAndExit()
- }
-*/
-
// after go-args MustParse & user configuration
// the gui package can pull out the final settings and init() the GO Plugin GUI Toolkit
func postMustParse(s string) string {
@@ -105,3 +72,4 @@ func (g *GuiPrep) Start() error {
}
return nil
}
+*/
diff --git a/interface.go b/interface.go
index 0dad2ac..8363a63 100644
--- a/interface.go
+++ b/interface.go
@@ -33,6 +33,12 @@ type examplesI interface {
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()
@@ -49,13 +55,15 @@ func findAppInfo(tmp interface{}) {
if tmp, ok := tmp.(buildtimeI); ok {
myAuto.buildtime = tmp.Buildtime
} else {
- // panic("you need to make the function argv.Appname()")
+ // panic("your app is missing (argv) func Buildtime() (string, string)")
}
if tmp, ok := tmp.(examplesI); ok {
myAuto.examples = tmp.Examples
- } else {
- // panic("you need to make the function argv.Appname()")
+ }
+
+ if tmp, ok := tmp.(guiI); ok {
+ myAuto.guiFunc = tmp.ArgvGui
}
if tmp, ok := tmp.(autoFuncI); ok {
diff --git a/structs.go b/structs.go
index 04e011d..01a6f56 100644
--- a/structs.go
+++ b/structs.go
@@ -32,6 +32,7 @@ type AutoArgs struct {
buildtime func() (string, string) // some examples
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
autoFunc func(*Auto) // also a function for autocomplete
+ guiFunc func() error // enables Gui functions
err error // store any errors from argv
}
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 942bd24..21aebed 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -18,6 +18,14 @@ func Autocomplete(dest any) *Auto {
myAuto = new(AutoArgs) // todo: redo this
findAppInfo(dest) // parses back to main() for argv info
+ if myAuto.guiFunc != nil {
+ // register gui args
+ myAuto.guiFunc()
+ // log.Info("gui init")
+ } else {
+ // log.Info("no gui init")
+ }
+
// load the argv history from the protobuf file
all := NewAutos()
err := config.LoadCache(all, "argv", myAuto.appName) // loads ~/.cache/argv/forge.pb
@@ -32,7 +40,7 @@ func Autocomplete(dest any) *Auto {
// try to register bash args for go-args
arg.Register(&argBash)
- arg.Register(&argGui)
+ // arg.Register(&argGui)
// user is trying to setup bash or zsh autocomplete
// --bash or --zsh is the first os.Args