diff options
| author | Jeff Carr <[email protected]> | 2025-10-19 04:39:13 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-19 04:39:13 -0500 | 
| commit | 7e204190a6c40815bcc37aed4ae7f473429a7c0f (patch) | |
| tree | 0b76b33104a3cf13c82dcf05c870085d9d8e83b0 | |
| parent | 6fb037663859bc50ac1d5bac1fdbfc722b1ab23d (diff) | |
new argvv0.5.29
| -rw-r--r-- | argv.custom.go | 48 | ||||
| -rw-r--r-- | argv.struct.go (renamed from argv.go) | 54 | ||||
| -rw-r--r-- | argv.template.go | 71 | ||||
| -rw-r--r-- | doProto.go | 6 | ||||
| -rw-r--r-- | generateHeader.go | 5 | ||||
| -rw-r--r-- | main.go | 14 | ||||
| -rw-r--r-- | structs.go | 6 | 
7 files changed, 132 insertions, 72 deletions
diff --git a/argv.custom.go b/argv.custom.go new file mode 100644 index 0000000..5480a34 --- /dev/null +++ b/argv.custom.go @@ -0,0 +1,48 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( +	"os" + +	"go.wit.com/lib/protobuf/argvpb" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +var APPNAME string = "autogenpb" + +func (a args) Description() string { +	return "go.wit.com/apps/autogenpb " + VERSION + "    Built on " + BUILDTIME + ` + +From a .proto file, autogenpb will: + +	* auto generate Sort(), Marshal() and GUI() functions in .pb.go files +	* auto format the .proto file (like goimport does for .go files) +	* encourages (enforces?) plural struct names (like rails) + +See the sources for an example .proto files + +Example usage: + +	autogenpb --proto foo.proto --package main +` +} + +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.Cmd == "" { +		base := []string{"--bash", "--proto", "--regret", "--debug", "--renumber", "--reformat", "--delete", "--dry-run"} +		pb.SendStrings(base) +	} else { +		pb.SubCommand(pb.Goargs...) +	} +	os.Exit(0) +} @@ -3,12 +3,6 @@  package main -import ( -	"os" - -	"go.wit.com/lib/protobuf/argvpb" -) -  /*  	this parses the command line arguements @@ -36,51 +30,3 @@ type args struct {  	GoPath    string `arg:"--gopath"                   help:"the gopath of this repo"`  	Identify  string `arg:"--identify"                 help:"identify file"`  } - -func (a args) Description() string { -	return "go.wit.com/apps/autogenpb " + VERSION + "    Built on " + BUILDTIME + ` - -From a .proto file, autogenpb will: - -	* auto generate Sort(), Marshal() and GUI() functions in .pb.go files -	* auto format the .proto file (like goimport does for .go files) -	* encourages (enforces?) plural struct names (like rails) - -See the sources for an example .proto files - -Example usage: - -	autogenpb --proto foo.proto --package main -` -} - -/* -	handles shell autocomplete -*/ - -func (args) Appname() string { -	return ARGNAME -} - -func (args) MatchClean() string { -	return "foo.proto bar.proto" -} - -func (args) Buildtime() (string, string) { -	return BUILDTIME, VERSION -} - -func (args) Version() string { -	return argvpb.StandardVersion(ARGNAME, VERSION, BUILDTIME) -} - -// sends the strings to bash or zsh that will be your options -func (a args) SendCompletionStrings(pb *argvpb.Argv) { -	if pb.Cmd == "" { -		base := []string{"--bash", "--proto", "--regret", "--debug", "--renumber", "--reformat", "--delete", "--dry-run"} -		pb.SendStrings(base) -	} else { -		pb.SubCommand(pb.Goargs...) -	} -	os.Exit(0) -} diff --git a/argv.template.go b/argv.template.go new file mode 100644 index 0000000..cd4421d --- /dev/null +++ b/argv.template.go @@ -0,0 +1,71 @@ +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/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 me.argv.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 +} @@ -36,12 +36,12 @@ func doProto(argvProto string) (string, error) {  	if argv.Clean {  		doClean(pf.Filebase) -		me.sh.GoodExit("doClean() ran") +		me.argv.GoodExit("doClean() ran")  	}  	if argv.Mtime {  		doMtime(pf.Filebase) -		me.sh.GoodExit("doClean() ran") +		me.argv.GoodExit("doClean() ran")  	}  	if argv.ReFormat { @@ -63,7 +63,7 @@ func doProto(argvProto string) (string, error) {  	}  	if doMtime(pf.Filebase) { -		me.sh.GoodExit(pf.Filename + " did not change") +		me.argv.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 72fdc9e..2aa7c5e 100644 --- a/generateHeader.go +++ b/generateHeader.go @@ -8,7 +8,6 @@ import (  	"io"  	"os" -	"go.wit.com/lib/protobuf/argvpb"  	"go.wit.com/log"  ) @@ -20,7 +19,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, "// ", argvpb.StandardVersion(ARGNAME, VERSION, BUILDTIME)) +	fmt.Fprintln(w, "// ", me.argv.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, "") @@ -32,7 +31,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, "// ", argvpb.StandardVersion(ARGNAME, VERSION, BUILDTIME)) +	fmt.Fprintln(w, "// ", me.argv.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, "//") @@ -24,15 +24,9 @@ import (  	"go.wit.com/log"  ) -// sent via -ldflags -var VERSION string -var BUILDTIME string - -var ARGNAME string = "autogenpb" -  func main() {  	me = new(mainType) -	me.sh = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args +	me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args  	me.pb = new(Files)  	var s string  	var err error @@ -51,9 +45,9 @@ func main() {  	// safe exits back to your shell (with timing and toolkit close)  	if err != nil { -		me.sh.BadExit(s, err) +		me.argv.BadExit(s, err)  	} -	me.sh.GoodExit(s) +	me.argv.GoodExit(s)  }  func okExit(s string) { @@ -73,7 +67,7 @@ func doPrecheck() (string, error) {  	if argv.Proto == "" {  		// todo: run on every .proto file  		log.Info("todo: run on all .proto files") -		me.sh.WriteHelp() +		argv.WriteHelp()  		return "you must provide --proto <protoname>.proto", errors.New("need .proto")  	} @@ -4,6 +4,7 @@  package main  import ( +	"go.wit.com/dev/alexflint/arg"  	"go.wit.com/lib/protobuf/argvpb"  ) @@ -11,6 +12,7 @@ var me *mainType  // this app's variables  type mainType struct { -	sh *argvpb.Argv // shell autocomplete -	pb *Files       // all the proto files as they get parsed (into another protobuf file) +	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)  }  | 
