cleanup as much junk as possible
This commit is contained in:
parent
25ae7fca5c
commit
88e4359cde
48
argv.go
48
argv.go
|
@ -10,48 +10,28 @@ var argv args
|
||||||
|
|
||||||
type args struct {
|
type args struct {
|
||||||
Package string `arg:"--package" help:"the package name"`
|
Package string `arg:"--package" help:"the package name"`
|
||||||
// LoBase string `arg:"--lobase" help:"lowercase basename"`
|
Proto string `arg:"--proto" help:"the .proto filename"`
|
||||||
// UpBase string `arg:"--upbase" help:"uppercase basename"`
|
Mutex bool `arg:"--mutex" default:"true" help:"insert a mutex into protoc .pb.go file"`
|
||||||
Proto string `arg:"--proto" help:"the .proto filename"`
|
Delete bool `arg:"--delete" help:"use delete with copy experiment"`
|
||||||
Append string `arg:"--append" help:"will keep this key unique on append"`
|
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
||||||
Sort []string `arg:"-s,--sort,separate" help:"how and what to sort on"`
|
GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
|
||||||
Marshal []string `arg:"--marshal" help:"what to marshal on"`
|
GoPath string `arg:"--gopath" help:"the gopath of this repo"`
|
||||||
NoMarshal bool `arg:"--no-marshal" help:"do not make a marshal.pb.go file"`
|
|
||||||
NoSort bool `arg:"--no-sort" help:"do not make a sort.pb.go file"`
|
|
||||||
Mutex bool `arg:"--mutex" default:"true" help:"add mutex in protoc autogen file"`
|
|
||||||
DryRun bool `arg:"--dry-run" help:"show what would be run"`
|
|
||||||
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"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a args) Description() string {
|
func (a args) Description() string {
|
||||||
return `
|
return "autogenpb " + VERSION + " Built on " + BUILDTIME + `
|
||||||
autogenpb tries to generate a sort.pb.go file for a protobuf
|
|
||||||
|
|
||||||
Install with:
|
Auto Generate protocol buffer Sort() and Marshal() functions
|
||||||
|
|
||||||
go install go.wit.com/apps/autogenpb@latest
|
go install go.wit.com/apps/autogenpb@latest
|
||||||
|
|
||||||
More information at:
|
The protobuf requires a 'standard' .proto format.
|
||||||
|
See the git sources for an example .proto file.
|
||||||
https://go.wit.com/
|
|
||||||
|
|
||||||
The protobuf is assumed to have a 'standard' format.
|
|
||||||
|
|
||||||
That is the .proto file:
|
|
||||||
|
|
||||||
* only defines one thing and it's the same name as the file
|
|
||||||
* uses the concept of 'plural' (like ruby on rails)
|
|
||||||
This means, the file should be "apples.proto" and inside
|
|
||||||
have 'message Apple' and 'message Apples'
|
|
||||||
The "message Apples" should have a repeated Apple apples
|
|
||||||
|
|
||||||
There is an example in the code:
|
|
||||||
|
|
||||||
go-clone go.wit.com/apps/autogenpb
|
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
func (args) Version() string {
|
func (args) Version() string {
|
||||||
return "go-clone " + VERSION + " Built on " + BUILDTIME
|
return "autogenpb " + VERSION + " Built on " + BUILDTIME
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
5
main.go
5
main.go
|
@ -25,11 +25,6 @@ import (
|
||||||
var VERSION string
|
var VERSION string
|
||||||
var BUILDTIME string
|
var BUILDTIME string
|
||||||
|
|
||||||
var sortmap map[string]string
|
|
||||||
var marshalKeys []string
|
|
||||||
|
|
||||||
// var uniqueKeys []string
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
pp := arg.MustParse(&argv)
|
pp := arg.MustParse(&argv)
|
||||||
|
|
||||||
|
|
34
sort.go
34
sort.go
|
@ -1,27 +1,37 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (pb *Files) makeNewSortfile(pf *File) error {
|
// this file is named poorly. It has more than Sort()
|
||||||
f, _ := os.OpenFile(pf.Filebase+".newsort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
|
||||||
|
|
||||||
header(f, pf)
|
func (pb *Files) makeNewSortfile(pf *File) error {
|
||||||
pf.syncLock(f)
|
w, _ := os.OpenFile(pf.Filebase+".sort.pb.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||||
|
|
||||||
|
header(w, pf)
|
||||||
|
pf.syncLock(w)
|
||||||
|
|
||||||
if argv.Mutex {
|
if argv.Mutex {
|
||||||
// use the mutex lock from the modified protoc.pb.go file
|
// use the mutex lock from the modified protoc.pb.go file
|
||||||
pf.Bases.Lockname = "all.Lock"
|
pf.Bases.Lockname = "all.Lock"
|
||||||
}
|
}
|
||||||
|
|
||||||
pf.Base.iterTop(f)
|
pf.Base.iterTop(w)
|
||||||
pf.Base.iterNext(f)
|
pf.Base.iterNext(w)
|
||||||
pf.iterSelect(f)
|
pf.selectAllFunc(w)
|
||||||
pf.appendUnique(f) // Append() enforce no unique keys
|
pf.iterSelect(w)
|
||||||
pf.iterSortBy(f)
|
|
||||||
pf.iterAll(f)
|
fmt.Fprintln(w, "// maybe seperate files here?")
|
||||||
pf.iterDelete(f)
|
|
||||||
pf.iterFind(f)
|
pf.appendUnique(w) // Append() enforce no unique keys
|
||||||
|
pf.sortByFunc(w)
|
||||||
|
if argv.Delete {
|
||||||
|
pf.deleteWithCopyFunc(w)
|
||||||
|
} else {
|
||||||
|
pf.deleteFunc(w)
|
||||||
|
}
|
||||||
|
pf.findFunc(w)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
12
sortFunc.go
12
sortFunc.go
|
@ -61,7 +61,7 @@ func (msg *MsgName) iterNext(w io.Writer) {
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pf *File) iterAll(w io.Writer) {
|
func (pf *File) selectAllFunc(w io.Writer) {
|
||||||
var BASES string = pf.Bases.Name
|
var BASES string = pf.Bases.Name
|
||||||
var BASE string = pf.Base.Name
|
var BASE string = pf.Base.Name
|
||||||
var LOCK string = pf.Bases.Lockname
|
var LOCK string = pf.Bases.Lockname
|
||||||
|
@ -82,7 +82,7 @@ func (pf *File) iterAll(w io.Writer) {
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pf *File) iterSortBy(w io.Writer) {
|
func (pf *File) sortByFunc(w io.Writer) {
|
||||||
var BASES string = pf.Bases.Name
|
var BASES string = pf.Bases.Name
|
||||||
var BASE string = pf.Base.Name
|
var BASE string = pf.Base.Name
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func (pf *File) appendUnique(w io.Writer) {
|
||||||
fmt.Fprintln(w, "")
|
fmt.Fprintln(w, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pf *File) iterReplace(w io.Writer) {
|
func (pf *File) replaceFunc(w io.Writer) {
|
||||||
var MSG string = pf.Bases.Name
|
var MSG string = pf.Bases.Name
|
||||||
var BASE string = pf.Base.Name
|
var BASE string = pf.Base.Name
|
||||||
var LOCK string = pf.Bases.Lockname
|
var LOCK string = pf.Bases.Lockname
|
||||||
|
@ -217,7 +217,7 @@ func (pf *File) iterReplace(w io.Writer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pf *File) iterDelete(w io.Writer) {
|
func (pf *File) deleteFunc(w io.Writer) {
|
||||||
var MSG string = pf.Bases.Name
|
var MSG string = pf.Bases.Name
|
||||||
var LOCK string = pf.Bases.Lockname
|
var LOCK string = pf.Bases.Lockname
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ func (pf *File) iterDelete(w io.Writer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct
|
// this tries to return the deleted one but is wrong/gives warning if mutex lock is in struct
|
||||||
func (pf *File) iterDeleteWithCopy(w io.Writer) {
|
func (pf *File) deleteWithCopyFunc(w io.Writer) {
|
||||||
var MSG string = pf.Bases.Name
|
var MSG string = pf.Bases.Name
|
||||||
var BASE string = pf.Base.Name
|
var BASE string = pf.Base.Name
|
||||||
var LOCK string = pf.Bases.Lockname
|
var LOCK string = pf.Bases.Lockname
|
||||||
|
@ -266,7 +266,7 @@ func (pf *File) iterDeleteWithCopy(w io.Writer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pf *File) iterFind(w io.Writer) {
|
func (pf *File) findFunc(w io.Writer) {
|
||||||
var MSG string = pf.Bases.Name
|
var MSG string = pf.Bases.Name
|
||||||
var BASE string = pf.Base.Name
|
var BASE string = pf.Base.Name
|
||||||
var LOCK string = pf.Bases.Lockname
|
var LOCK string = pf.Bases.Lockname
|
||||||
|
|
Loading…
Reference in New Issue