diff options
| author | Jeff Carr <[email protected]> | 2025-10-08 10:42:18 -0500 | 
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-08 10:42:18 -0500 | 
| commit | 6feac2ad08250625fd29951b5769655f683b3d03 (patch) | |
| tree | 59ba4fdea6700be080700aedd7c6678835ffec19 | |
| parent | 0c313d9cc066af084b93b28e1320b502d93dbda6 (diff) | |
| -rw-r--r-- | README | 6 | ||||
| -rw-r--r-- | argv.go | 3 | ||||
| -rw-r--r-- | file.proto | 1 | ||||
| -rw-r--r-- | main.go | 40 | ||||
| -rw-r--r-- | protoReformat.go | 18 | ||||
| -rw-r--r-- | structs.go | 16 | 
6 files changed, 65 insertions, 19 deletions
@@ -1,5 +1,7 @@  # This app auto-generates *.pb.go files  # +# it'll also auto-increment with --renumber +#  # It assumes you are doing GO development in ~/go/src  # 	Although it might work with go.work directory setups  #	I haven't tested that much yet because I haven't had time @@ -18,6 +20,10 @@  * FindBy() functions  * DeleteBy() functions  * AppendBy() functions +* Http() functions +* Gui() functions +* PrintTable() functions +* Save() & Load() functions  # See the examples/ for a sample fruit.proto file that documents what is needed @@ -29,6 +29,7 @@ type args struct {  	Debug     bool   `arg:"--debug"                    help:"enable debugging information"`  	Comments  bool   `arg:"--format-comments"          help:"enforce parseable comments in a .proto file"`  	NoFormat  bool   `arg:"--no-format"                help:"do not auto-reformat the .proto file"` +	Renumber  bool   `arg:"--renumber"                 help:"renumber everything. obviously breaks backwards compatiblity"`  	GoSrc     string `arg:"--go-src"                   help:"default is ~/go/src. could be set to your go.work path"`  	GoPath    string `arg:"--gopath"                   help:"the gopath of this repo"`  	Identify  string `arg:"--identify"                 help:"identify file"` @@ -69,7 +70,7 @@ func (args) Buildtime() (string, string) {  func (a args) DoAutoComplete(pb *prep.Auto) {  	if pb.Cmd == "" { -		pb.Autocomplete3([]string{"--bash", "--proto", "--regret", "--debug", "--delete", "--dry-run", "--version"}) +		pb.Autocomplete3([]string{"--bash", "--proto", "--regret", "--debug", "--renumber", "--delete", "--dry-run", "--version"})  	} else {  		pb.SubCommand(pb.Goargs...)  	} @@ -79,6 +79,7 @@ message FormatMsg {          Type                  type              = 9;  // yep. type. yep. that's what this is for          bool                  padAfter          = 10;          bool                  isEmpty           = 11; // true when things like: message blah {} +        int32                 counter           = 12; // used to check ints increment  }  message Find {          string                parent            = 1;  // `autogenpb:unique` File @@ -35,10 +35,9 @@ var ARGNAME string = "autogenpb"  // var fsort *os.File // the sort.pb.go output file  func main() { -	auto := prep.Bash(&argv) // add support for bash autocomplete with go-arg - -	var pb *Files -	pb = new(Files) +	me = new(mainType) +	me.sh = prep.Bash(&argv) // add support for bash autocomplete with go-arg +	me.pb = new(Files)  	if argv.Identify != "" {  		if err := doIdentify(argv.Identify); err != nil { @@ -50,7 +49,7 @@ func main() {  	// you need a proto file  	if argv.Proto == "" {  		log.Info("you must provide --proto <filename>") -		auto.WriteHelp() +		me.sh.WriteHelp()  		os.Exit(-1)  	} @@ -64,15 +63,19 @@ func main() {  		os.Exit(-1)  	} +	doProto(argv.Proto) +} + +func doProto(argvProto string) error {  	if argv.Format { -		protoReformatComments(argv.Proto) +		protoReformatComments(argvProto)  		// time.Sleep(5 * time.Second) -		protoReformat(argv.Proto) +		protoReformat(argvProto)  		log.Info("format done")  		okExit("")  	}  	if argv.Comments { -		protoReformatComments(argv.Proto) +		protoReformatComments(argvProto)  		okExit("")  	} @@ -82,11 +85,11 @@ func main() {  	}  	pf := new(File) -	pb.Files = append(pb.Files, pf) -	pf.Filename = argv.Proto +	me.pb.Files = append(me.pb.Files, pf) +	pf.Filename = argvProto  	pf.IterMap = make(map[string]string) -	pf.Filebase = strings.TrimSuffix(argv.Proto, ".proto") +	pf.Filebase = strings.TrimSuffix(argvProto, ".proto")  	// parse sort & marshal options from the .proto file  	// this goes through the .proto files and looks @@ -97,7 +100,7 @@ func main() {  	}  	if !argv.NoFormat { -		protoReformat(argv.Proto) +		protoReformat(argvProto)  	}  	if pf.Bases == nil { @@ -179,7 +182,7 @@ func main() {  		// checkCmd("protoc")  		// checkCmd("protoc-gen-go") -		if err := pb.protocBuild(pf); err != nil { +		if err := me.pb.protocBuild(pf); err != nil {  			badExit(err)  		} @@ -187,7 +190,7 @@ func main() {  	os.Chdir(startpwd)  	// try to add the Mutex to the pb.go file -	if err := pb.addMutex(pf); err != nil { +	if err := me.pb.addMutex(pf); err != nil {  		badExit(err)  	} @@ -198,27 +201,28 @@ func main() {  	}  	// make the marshal.pb.go file -	pb.marshal(pf) +	me.pb.marshal(pf)  	// make the sort.pb.go file -	if err := pb.makeNewSortfile(pf); err != nil { +	if err := me.pb.makeNewSortfile(pf); err != nil {  		badExit(err)  	}  	if pf.DoGui { -		if err := pb.makeGuiFile(pf); err != nil { +		if err := me.pb.makeGuiFile(pf); err != nil {  			badExit(err)  		}  	}  	if pf.DoHTTP { -		if err := pb.makeHTTPFile(pf); err != nil { +		if err := me.pb.makeHTTPFile(pf); err != nil {  			badExit(err)  		}  	}  	log.Info("")  	log.Info("you may have to run 'goimport -w *.go' on the new *pb.go files")  	log.Info("") +	return nil  }  func okExit(s string) { diff --git a/protoReformat.go b/protoReformat.go index 8b49879..77cc723 100644 --- a/protoReformat.go +++ b/protoReformat.go @@ -8,6 +8,7 @@ import (  	"iter"  	"os"  	"regexp" +	"strconv"  	"strings"  	sync "sync" @@ -565,6 +566,23 @@ func (msg *FormatMsg) formatVarLine(line string, dbg string) string {  	vartype, varname, id, end := tokenMsgVar(line)  	end = strings.TrimSpace(end) + +	if argv.Renumber { +		// allows auto-renumbering +		newint, err := strconv.Atoi(id) +		if err != nil { +			log.Info("i is wrong", msg, err) +			panic("what?") +		} +		msg.Counter += 1 +		if int(msg.Counter) != newint { +			// panic("you can't count") +			log.Info("counter is wrong", newint, id, msg.Header) +		} +		id = fmt.Sprintf("%d", msg.Counter) +	} +	// log.Info("counter =", newint, msg.Header) +	// msg.Counter = int32(newint)  	id = id + ";"  	newline := fmt.Sprintf(hmm, vartype, varname, id, end) diff --git a/structs.go b/structs.go new file mode 100644 index 0000000..86985d2 --- /dev/null +++ b/structs.go @@ -0,0 +1,16 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( +	"go.wit.com/lib/gui/prep" +) + +var me *mainType + +// this app's variables +type mainType struct { +	sh *prep.Auto // shell autocomplete +	pb *Files     // all the proto files as they get parsed (into another protobuf file) +}  | 
