better append/sort stuff
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
908c905675
commit
98b366e2df
53
main.go
53
main.go
|
@ -9,6 +9,8 @@ import (
|
||||||
"github.com/alexflint/go-arg"
|
"github.com/alexflint/go-arg"
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
"golang.org/x/text/cases"
|
||||||
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sent via -ldflags
|
// sent via -ldflags
|
||||||
|
@ -37,7 +39,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// you need --upbase and --lobase
|
// you need --upbase and --lobase
|
||||||
if argv.UpBase == "" {
|
if argv.Proto == "" {
|
||||||
pp.WriteHelp(os.Stdout)
|
pp.WriteHelp(os.Stdout)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
@ -55,18 +57,20 @@ func main() {
|
||||||
sortmap := make(map[string]string)
|
sortmap := make(map[string]string)
|
||||||
sortmap["package"] = packageName
|
sortmap["package"] = packageName
|
||||||
sortmap["protobase"] = protobase
|
sortmap["protobase"] = protobase
|
||||||
sortmap["base"] = argv.LoBase
|
if argv.LoBase == "" {
|
||||||
|
// if not set, assumed to be protobase
|
||||||
|
sortmap["base"] = protobase
|
||||||
|
} else {
|
||||||
|
sortmap["base"] = argv.LoBase
|
||||||
|
}
|
||||||
sortmap["lock"] = sortmap["base"] + "sLock" // is nonglobal and plural
|
sortmap["lock"] = sortmap["base"] + "sLock" // is nonglobal and plural
|
||||||
sortmap["Base"] = argv.UpBase
|
if argv.UpBase == "" {
|
||||||
sortmap["Bases"] = sortmap["Base"] + "s"
|
sortmap["Base"] = cases.Title(language.English, cases.NoLower).String(protobase)
|
||||||
|
sortmap["Bases"] = sortmap["Base"] + "s"
|
||||||
sortparts := strings.Split(argv.Sort[0], ",")
|
} else {
|
||||||
sortmap["sortBy"] = sortparts[0]
|
sortmap["Base"] = argv.UpBase
|
||||||
sortmap["sortKey"] = sortparts[1]
|
sortmap["Bases"] = sortmap["Base"] + "s"
|
||||||
|
}
|
||||||
// will keep this key unique if defined
|
|
||||||
sortmap["append"] = argv.Append
|
|
||||||
|
|
||||||
|
|
||||||
if argv.DryRun {
|
if argv.DryRun {
|
||||||
for k, v := range sortmap {
|
for k, v := range sortmap {
|
||||||
|
@ -81,11 +85,26 @@ func main() {
|
||||||
syncLock(f, sortmap)
|
syncLock(f, sortmap)
|
||||||
iterTop(f, sortmap)
|
iterTop(f, sortmap)
|
||||||
iterNext(f, sortmap)
|
iterNext(f, sortmap)
|
||||||
iterSort(f, sortmap)
|
|
||||||
iterAppend(f, sortmap)
|
// setup Append() functions
|
||||||
if argv.Append == "" {
|
if argv.Append == "" {
|
||||||
// do nothing. enforce no unique keys
|
iterAppend(f, sortmap) // Append() enforce no unique keys
|
||||||
} else {
|
} else {
|
||||||
|
iterAppend(f, sortmap) // Append() enforce no unique keys
|
||||||
|
sortmap["append"] = argv.Append
|
||||||
|
iterAppend(f, sortmap) // Append() enforce unique key argv.Append
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup Sort() functions
|
||||||
|
if len(argv.Sort) == 0 {
|
||||||
|
// don't do any sorting
|
||||||
|
} else {
|
||||||
|
sortparts := strings.Split(argv.Sort[0], ",")
|
||||||
|
sortmap["sortBy"] = sortparts[0]
|
||||||
|
sortmap["sortKey"] = sortparts[1]
|
||||||
|
|
||||||
|
iterSort(f, sortmap)
|
||||||
|
|
||||||
// add ReplaceKey()
|
// add ReplaceKey()
|
||||||
iterDelete(f, sortmap)
|
iterDelete(f, sortmap)
|
||||||
iterReplace(f, sortmap)
|
iterReplace(f, sortmap)
|
||||||
|
@ -235,8 +254,8 @@ func iterAppend(w io.Writer, names map[string]string) {
|
||||||
if names["append"] == "" {
|
if names["append"] == "" {
|
||||||
fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool {")
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool {")
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool { // todo: make unique name here")
|
// fmt.Fprintln(w, "func (all *"+names["Bases"]+") Append(newP *"+names["Base"]+") bool { // todo: make unique name here")
|
||||||
// fmt.Fprintln(w, "func (all *"+names["Bases"]+") AppendUnique(newP *"+names["Base"]+") bool {")
|
fmt.Fprintln(w, "func (all *"+names["Bases"]+") AppendUnique(newP *"+names["Base"]+") bool {")
|
||||||
}
|
}
|
||||||
fmt.Fprintln(w, " "+names["lock"]+".Lock()")
|
fmt.Fprintln(w, " "+names["lock"]+".Lock()")
|
||||||
fmt.Fprintln(w, " defer "+names["lock"]+".Unlock()")
|
fmt.Fprintln(w, " defer "+names["lock"]+".Unlock()")
|
||||||
|
|
|
@ -3,10 +3,11 @@ BUILDTIME = $(shell date +%Y.%m.%d)
|
||||||
|
|
||||||
test: vet
|
test: vet
|
||||||
|
|
||||||
all: clean test.pb.go run
|
all: clean test.pb.go forgeConfig.pb.go run
|
||||||
|
|
||||||
run:
|
run:
|
||||||
../autogenpb --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" --marshal GitTags --append Refname
|
../autogenpb --proto test.proto --lobase gitTag --upbase GitTag --sort "ByPath,Refname" --marshal GitTags --append Refname
|
||||||
|
../autogenpb --proto forgeConfig.proto --sort "ByPath,GoPath" --append GoPath
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
@GO111MODULE=off go vet
|
@GO111MODULE=off go vet
|
||||||
|
@ -31,3 +32,8 @@ test.pb.go: test.proto
|
||||||
cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/apps/autogenpb/testautogen \
|
cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/apps/autogenpb/testautogen \
|
||||||
--go_opt=Mtest.proto=go.wit.com/apps/autogenpb/testautogen \
|
--go_opt=Mtest.proto=go.wit.com/apps/autogenpb/testautogen \
|
||||||
test.proto
|
test.proto
|
||||||
|
|
||||||
|
forgeConfig.pb.go: forgeConfig.proto
|
||||||
|
cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/apps/autogenpb/testautogen \
|
||||||
|
--go_opt=MforgeConfig.proto=go.wit.com/apps/autogenpb/testautogen \
|
||||||
|
forgeConfig.proto
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package testautogen;
|
||||||
|
|
||||||
|
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||||
|
|
||||||
|
// define 3 branches. that is all that is supported
|
||||||
|
// the term 'master' is used in the code because 'main' is a reserved word in golang already
|
||||||
|
// allow 'read only' and 'private' flags
|
||||||
|
// package names sometimes must be different than the binary name
|
||||||
|
// for example 'zookeeper' is packaged as 'zookeeper-go'
|
||||||
|
// due to the prior apache foundation project. This happens and is ok!
|
||||||
|
message ForgeConfig {
|
||||||
|
string goPath = 1; // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo"
|
||||||
|
|
||||||
|
bool writable = 2; // if you have write access to the repo
|
||||||
|
bool readOnly = 3; // the opposite, but needed for now because I don't know what I'm doing
|
||||||
|
bool private = 4; // if the repo can be published
|
||||||
|
bool directory = 5; // everything in this directory should use these writable & private values
|
||||||
|
bool favorite = 6; // you like this. always git clone/go clone this repo
|
||||||
|
bool interesting = 7; // this is something interesting you found and want to remember it
|
||||||
|
|
||||||
|
string masterBranchName = 8; // git 'main' or 'master' branch name
|
||||||
|
string develBranchName = 9; // whatever the git 'devel' branch name is
|
||||||
|
string userBranchName = 10; // whatever your username branch is
|
||||||
|
|
||||||
|
string debName = 11; // the actual name used with 'apt install' (or distro apt equivalent.
|
||||||
|
// todo: appeal to everyone to alias 'apt' on rhat, gentoo, arch, etc to alias 'apt install'
|
||||||
|
// so we can make easier instructions for new linux users. KISS
|
||||||
|
|
||||||
|
google.protobuf.Timestamp verstamp = 12; // the git commit timestamp of the version
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: autogen 'sort', 'marshal'
|
||||||
|
message ForgeConfigs {
|
||||||
|
string uuid = 1; // could be useful for /usr/share/file/magic someday?
|
||||||
|
string version = 2; // could be used for protobuf schema change violations?
|
||||||
|
repeated ForgeConfig ForgeConfigs = 3;
|
||||||
|
}
|
Loading…
Reference in New Issue