summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-26 08:55:11 -0500
committerJeff Carr <[email protected]>2025-10-26 08:55:11 -0500
commit8385540f09ca42ef9443fddfd1a89e76ad5f1329 (patch)
tree45cc8b4da0d6a68eee2f4c80cfffa540d876b0a0
parent6ccf7c45a24bf55a8d8ccc5b452dc3496aeac90e (diff)
new argvpb changes
-rw-r--r--argv.go (renamed from argv.struct.go)0
-rw-r--r--argv.template.go72
-rw-r--r--complete.go (renamed from argv.custom.go)28
-rw-r--r--doProto.go7
-rw-r--r--generateHeader.go5
-rw-r--r--main.go8
-rw-r--r--structs.go6
7 files changed, 34 insertions, 92 deletions
diff --git a/argv.struct.go b/argv.go
index 0649e16..0649e16 100644
--- a/argv.struct.go
+++ b/argv.go
diff --git a/argv.template.go b/argv.template.go
deleted file mode 100644
index 4e6f4f7..0000000
--- a/argv.template.go
+++ /dev/null
@@ -1,72 +0,0 @@
-package main
-
-// these are stubbed in functions needed
-// just copy this file from another working app for now
-// you shouldn't need to change anything here
-// TODO: clean this up in argv
-
-import (
- "os"
-
- "go.wit.com/dev/alexflint/arg"
- "go.wit.com/gui"
- "go.wit.com/lib/env"
- "go.wit.com/log"
-)
-
-func (args) InitArgv() (string, string, string) {
- return APPNAME, BUILDTIME, VERSION
-}
-
-// this function will send the current argv PB to go-args for parsing
-func (args) ParseFlags(flags []string) error {
- var err error
- if me.pp == nil {
- // log.Info("Parse Flags GOT flags:", flags)
- me.pp, err = arg.ParseFlags(flags, &argv)
- // panic("got to the app's ParseFlags()")
- } else {
- panic("me.pp was not nil")
- }
- return err
-}
-
-// add this funcgion: this will print the help
-func (args) WriteHelpForSubcommand(cmd string) error {
- me.pp.WriteHelpForSubcommand(os.Stderr, cmd)
- return nil
-}
-
-// this will print the help for the subcmd
-func (args) WriteHelpForAutocomplete(part string, subcmd ...string) error {
- return me.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, part, subcmd...)
-}
-
-func (args) WriteHelpForAutocompleteDebug(part string, subcmd ...string) error {
- f, _ := os.OpenFile("/tmp/argv.junk", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
- return me.pp.WriteHelpForAutocomplete(f, os.Stdout, part, subcmd...)
-}
-
-// add this funcgion: this will print the help
-func (args) WriteHelp() error {
- me.pp.WriteHelp(os.Stderr)
- return nil
-}
-
-func (args) Exit() {
- gui.UnloadToolkits()
- if env.Verbose() {
- log.Info("argv.Exit() called", APPNAME+".Exit()")
- }
- // remove this from the template for your app (or make one for youself if you need it)
- // forgeExit() // custom forge shutdown function
-}
-
-func (args) Help() string {
- return "got app help"
-}
-
-func (args) MustParse() error {
- me.pp = arg.MustParse(&argv)
- return nil
-}
diff --git a/argv.custom.go b/complete.go
index 3401eea..ae1dd12 100644
--- a/argv.custom.go
+++ b/complete.go
@@ -4,8 +4,10 @@
package main
import (
- "os"
+ "fmt"
+ "strings"
+ "go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/protobuf/argvpb"
)
@@ -32,17 +34,29 @@ Example usage:
`
}
+func (args) MustParse() error {
+ me.pp = arg.MustParse(&argv)
+ return nil
+}
+
func (args) MatchClean() string {
return "foo.proto bar.proto"
}
// sends the strings to bash or zsh that will be your options
-func (a args) SendCompletionStrings(pb *argvpb.Argv) {
- if pb.GetCmd() == "" {
+func (a args) SendCompletionStrings() error {
+ if argvpb.PB.GetCmd() == "" {
base := []string{"--bash", "--proto", "--regret", "--debug", "--renumber", "--reformat", "--delete", "--dry-run"}
- pb.SendStrings(base)
- } else {
- pb.SubCommand(pb.Goargs...)
+ fmt.Fprintf(argvpb.Stdout, " %s", strings.Join(base, " "))
+ return nil
+ }
+ var err error
+ if me.pp == nil {
+ me.pp, err = arg.ParseFlagsArgv(&argv)
+ if err != nil {
+ return err
+ }
}
- os.Exit(0)
+ err = me.pp.WriteHelpForAutocomplete(argvpb.PB.Partial, argvpb.PB.Real...)
+ return err
}
diff --git a/doProto.go b/doProto.go
index 5335ab9..6060f59 100644
--- a/doProto.go
+++ b/doProto.go
@@ -23,6 +23,7 @@ import (
"github.com/go-cmd/cmd"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
+ "go.wit.com/lib/protobuf/argvpb"
"go.wit.com/log"
)
@@ -36,12 +37,12 @@ func doProto(argvProto string) (string, error) {
if argv.Clean {
doClean(pf.Filebase)
- me.argv.GoodExit("doClean() ran")
+ argvpb.GoodExit("doClean() ran")
}
if argv.Mtime {
doMtime(pf.Filebase)
- me.argv.GoodExit("doClean() ran")
+ argvpb.GoodExit("doClean() ran")
}
if argv.ReFormat {
@@ -63,7 +64,7 @@ func doProto(argvProto string) (string, error) {
}
if doMtime(pf.Filebase) {
- me.argv.GoodExit(pf.Filename + " did not change")
+ argvpb.GoodExit(pf.Filename + " did not change")
} else {
log.Info("ctime check: need to re-run autogenpb")
}
diff --git a/generateHeader.go b/generateHeader.go
index eafc25b..c94b045 100644
--- a/generateHeader.go
+++ b/generateHeader.go
@@ -8,6 +8,7 @@ import (
"io"
"os"
+ "go.wit.com/lib/protobuf/argvpb"
"go.wit.com/log"
)
@@ -19,7 +20,7 @@ func pbHeaderComment(w io.Writer) {
fmt.Fprintln(w, "// user defined Mutex locks were auto added")
fmt.Fprintln(w, "//")
fmt.Fprintln(w, "// This file was autogenerated with autogenpb:")
- fmt.Fprintln(w, "// ", me.argv.Version())
+ fmt.Fprintln(w, "// ", argvpb.Version())
fmt.Fprintln(w, "// Theese sort.pb.go and marshal.pb.go files are autogenerated")
fmt.Fprintln(w, "// The autogenpb sources have example .proto files with instructions")
fmt.Fprintln(w, "")
@@ -31,7 +32,7 @@ func headerComment(w io.Writer) {
fmt.Fprintln(w, "// go install go.wit.com/apps/autogenpb@latest")
fmt.Fprintln(w, "//")
fmt.Fprintln(w, "// This file was autogenerated with autogenpb:")
- fmt.Fprintln(w, "// ", me.argv.Version())
+ fmt.Fprintln(w, "// ", argvpb.Version())
fmt.Fprintln(w, "// Theese sort.pb.go and marshal.pb.go files are autogenerated")
fmt.Fprintln(w, "// The autogenpb sources have example .proto files with instructions")
fmt.Fprintln(w, "//")
diff --git a/main.go b/main.go
index ea3de98..6645fb7 100644
--- a/main.go
+++ b/main.go
@@ -26,7 +26,7 @@ import (
func main() {
me = new(mainType)
- me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args
+ argvpb.Init(&argv, APPNAME, BUILDTIME, VERSION) // adds shell auto-complete
me.pb = new(Files)
var s string
var err error
@@ -45,9 +45,9 @@ func main() {
// safe exits back to your shell (with timing and toolkit close)
if err != nil {
- me.argv.BadExit(s, err)
+ argvpb.BadExit(s, err)
}
- me.argv.GoodExit(s)
+ argvpb.GoodExit(s)
}
func okExit(s string) {
@@ -67,7 +67,7 @@ func doPrecheck() (string, error) {
if argv.Proto == "" {
// todo: run on every .proto file
log.Info("todo: run on all .proto files")
- argv.WriteHelp()
+ me.pp.WriteHelp(os.Stdout)
return "you must provide --proto <protoname>.proto", errors.New("need .proto")
}
diff --git a/structs.go b/structs.go
index f74b90f..75e9891 100644
--- a/structs.go
+++ b/structs.go
@@ -5,14 +5,12 @@ package main
import (
"go.wit.com/dev/alexflint/arg"
- "go.wit.com/lib/protobuf/argvpb"
)
var me *mainType
// this app's variables
type mainType struct {
- argv *argvpb.Argv // more experiments for bash handling
- pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
- pb *Files // all the proto files as they get parsed (into another protobuf file)
+ pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
+ pb *Files // all the proto files as they get parsed (into another protobuf file)
}