parent
6e29eb7862
commit
28daefa6c5
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
/*
|
||||
this parses the command line arguements
|
||||
|
||||
this enables command line options from other packages like 'gui' and 'log'
|
||||
*/
|
||||
|
||||
var argv args
|
||||
|
||||
type args struct {
|
||||
Base string `arg:"--base" help:"basename"`
|
||||
Proto string `arg:"--proto" help:"the .proto filename"`
|
||||
}
|
||||
|
||||
func (a args) Description() string {
|
||||
return `
|
||||
autogenpb tries to generate a sort.pb.go file for a protobuf
|
||||
|
||||
Install with:
|
||||
|
||||
go install go.wit.com/apps/autogenpb@latest
|
||||
|
||||
More information at:
|
||||
|
||||
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 {
|
||||
return "go-clone " + VERSION + " Built on " + BUILDTIME
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.35.2-devel
|
||||
// protoc v3.21.12
|
||||
// source: gitTags.proto
|
||||
|
||||
package autogen
|
||||
|
||||
import (
|
||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||
reflect "reflect"
|
||||
sync "sync"
|
||||
)
|
||||
|
||||
const (
|
||||
// Verify that this generated code is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
|
||||
// Verify that runtime/protoimpl is sufficiently up-to-date.
|
||||
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
|
||||
)
|
||||
|
||||
type GitTag struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Refname string `protobuf:"bytes,1,opt,name=refname,proto3" json:"refname,omitempty"` // tag name. treated as unique
|
||||
Creatordate *timestamppb.Timestamp `protobuf:"bytes,2,opt,name=creatordate,proto3" json:"creatordate,omitempty"` // git creatordate
|
||||
Authordate *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=authordate,proto3" json:"authordate,omitempty"` // git creatordate
|
||||
Objectname string `protobuf:"bytes,4,opt,name=objectname,proto3" json:"objectname,omitempty"` // git hash
|
||||
Subject string `protobuf:"bytes,5,opt,name=subject,proto3" json:"subject,omitempty"` // git tag subject
|
||||
}
|
||||
|
||||
func (x *GitTag) Reset() {
|
||||
*x = GitTag{}
|
||||
mi := &file_gitTags_proto_msgTypes[0]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
|
||||
func (x *GitTag) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GitTag) ProtoMessage() {}
|
||||
|
||||
func (x *GitTag) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_gitTags_proto_msgTypes[0]
|
||||
if x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GitTag.ProtoReflect.Descriptor instead.
|
||||
func (*GitTag) Descriptor() ([]byte, []int) {
|
||||
return file_gitTags_proto_rawDescGZIP(), []int{0}
|
||||
}
|
||||
|
||||
func (x *GitTag) GetRefname() string {
|
||||
if x != nil {
|
||||
return x.Refname
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GitTag) GetCreatordate() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.Creatordate
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *GitTag) GetAuthordate() *timestamppb.Timestamp {
|
||||
if x != nil {
|
||||
return x.Authordate
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *GitTag) GetObjectname() string {
|
||||
if x != nil {
|
||||
return x.Objectname
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *GitTag) GetSubject() string {
|
||||
if x != nil {
|
||||
return x.Subject
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var File_gitTags_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_gitTags_proto_rawDesc = []byte{
|
||||
0x0a, 0x0d, 0x67, 0x69, 0x74, 0x54, 0x61, 0x67, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12,
|
||||
0x05, 0x67, 0x69, 0x74, 0x70, 0x62, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70,
|
||||
0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d,
|
||||
0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd6, 0x01, 0x0a, 0x06, 0x47, 0x69, 0x74, 0x54,
|
||||
0x61, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x66, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x66, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x3c, 0x0a, 0x0b,
|
||||
0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0b, 0x63,
|
||||
0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x12, 0x3a, 0x0a, 0x0a, 0x61, 0x75,
|
||||
0x74, 0x68, 0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a,
|
||||
0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66,
|
||||
0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, 0x75, 0x74, 0x68,
|
||||
0x6f, 0x72, 0x64, 0x61, 0x74, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x6f, 0x62, 0x6a, 0x65,
|
||||
0x63, 0x74, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63,
|
||||
0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x73, 0x75, 0x62, 0x6a, 0x65, 0x63, 0x74,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
file_gitTags_proto_rawDescOnce sync.Once
|
||||
file_gitTags_proto_rawDescData = file_gitTags_proto_rawDesc
|
||||
)
|
||||
|
||||
func file_gitTags_proto_rawDescGZIP() []byte {
|
||||
file_gitTags_proto_rawDescOnce.Do(func() {
|
||||
file_gitTags_proto_rawDescData = protoimpl.X.CompressGZIP(file_gitTags_proto_rawDescData)
|
||||
})
|
||||
return file_gitTags_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_gitTags_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
|
||||
var file_gitTags_proto_goTypes = []any{
|
||||
(*GitTag)(nil), // 0: gitpb.GitTag
|
||||
(*timestamppb.Timestamp)(nil), // 1: google.protobuf.Timestamp
|
||||
}
|
||||
var file_gitTags_proto_depIdxs = []int32{
|
||||
1, // 0: gitpb.GitTag.creatordate:type_name -> google.protobuf.Timestamp
|
||||
1, // 1: gitpb.GitTag.authordate:type_name -> google.protobuf.Timestamp
|
||||
2, // [2:2] is the sub-list for method output_type
|
||||
2, // [2:2] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
2, // [2:2] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_gitTags_proto_init() }
|
||||
func file_gitTags_proto_init() {
|
||||
if File_gitTags_proto != nil {
|
||||
return
|
||||
}
|
||||
type x struct{}
|
||||
out := protoimpl.TypeBuilder{
|
||||
File: protoimpl.DescBuilder{
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_gitTags_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 1,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
GoTypes: file_gitTags_proto_goTypes,
|
||||
DependencyIndexes: file_gitTags_proto_depIdxs,
|
||||
MessageInfos: file_gitTags_proto_msgTypes,
|
||||
}.Build()
|
||||
File_gitTags_proto = out.File
|
||||
file_gitTags_proto_rawDesc = nil
|
||||
file_gitTags_proto_goTypes = nil
|
||||
file_gitTags_proto_depIdxs = nil
|
||||
}
|
35
main.go
35
main.go
|
@ -4,19 +4,43 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/alexflint/go-arg"
|
||||
"go.wit.com/lib/gui/shell"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
// sent via -ldflags
|
||||
var VERSION string
|
||||
var BUILDTIME string
|
||||
|
||||
func main() {
|
||||
pp := arg.MustParse(&argv)
|
||||
|
||||
// for very new users or users unfamilar with the command line, this may help them
|
||||
if argv.Base == "help" || argv.Base == "?" {
|
||||
pp.WriteHelp(os.Stdout)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
cmd := []string{"go", "list", "-f", "'{{.Name}}'"}
|
||||
result := shell.Run(cmd)
|
||||
|
||||
packageName := strings.Join(result.Stdout, "\n")
|
||||
packageName = strings.TrimSpace(packageName)
|
||||
packageName = strings.Trim(packageName, "'")
|
||||
log.Info("packageName == ", packageName)
|
||||
|
||||
f, _ := os.OpenFile("test.sort.pb.go", os.O_WRONLY|os.O_CREATE, 0600)
|
||||
|
||||
sortmap := make(map[string]string)
|
||||
sortmap["package"] = "testautogen"
|
||||
sortmap["lock"] = "gitTagslock"
|
||||
sortmap["Base"] = "GitTag"
|
||||
sortmap["Bases"] = "GitTags"
|
||||
|
||||
sortmap["package"] = packageName
|
||||
sortmap["base"] = "gitTag"
|
||||
sortmap["lock"] = sortmap["base"] + "slock"
|
||||
sortmap["Base"] = "GitTag"
|
||||
sortmap["Bases"] = sortmap["Base"] + "s"
|
||||
|
||||
sortmap["sortBy"] = "ByPath"
|
||||
sortmap["sortKey"] = "Refname"
|
||||
|
||||
|
@ -96,7 +120,6 @@ func iterNext(w io.Writer, names map[string]string) {
|
|||
fmt.Fprintln(w, "")
|
||||
}
|
||||
|
||||
|
||||
func iterSort(w io.Writer, names map[string]string) {
|
||||
fmt.Fprintln(w, "func (all *"+names["Bases"]+") All() *"+names["Base"]+"Iterator {")
|
||||
fmt.Fprintln(w, " "+names["base"]+"Pointers := all.selectAll"+names["Base"]+"()")
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package main
|
||||
|
||||
import "log"
|
||||
import "go.wit.com/apps/autogenpb/testautogen"
|
||||
import (
|
||||
"log"
|
||||
|
||||
"go.wit.com/apps/autogenpb/testautogen"
|
||||
)
|
||||
|
||||
func main() {
|
||||
all := new(testautogen.GitTags)
|
||||
|
|
Loading…
Reference in New Issue