fix --debug
This commit is contained in:
parent
de7d698e19
commit
0a97886cd2
1
argv.go
1
argv.go
|
@ -20,6 +20,7 @@ type args struct {
|
||||||
Delete bool `arg:"--delete" help:"use delete with copy experiment"`
|
Delete bool `arg:"--delete" help:"use delete with copy experiment"`
|
||||||
DryRun bool `arg:"--dry-run" help:"check the .proto syntax, but don't do anything"`
|
DryRun bool `arg:"--dry-run" help:"check the .proto syntax, but don't do anything"`
|
||||||
Format bool `arg:"--format" help:"format the .proto file and exit"`
|
Format bool `arg:"--format" help:"format the .proto file and exit"`
|
||||||
|
Debug bool `arg:"--debug" help:"enable debugging information"`
|
||||||
Comments bool `arg:"--format-comments" help:"enforce parseable comments in a .proto file"`
|
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"`
|
NoFormat bool `arg:"--no-format" help:"do not auto-reformat the .proto file"`
|
||||||
GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
|
GoSrc string `arg:"--go-src" help:"default is ~/go/src. could be set to your go.work path"`
|
||||||
|
|
|
@ -110,7 +110,7 @@ proto-reformat-comments:
|
||||||
../autogenpb --proto signal.proto --format-comments
|
../autogenpb --proto signal.proto --format-comments
|
||||||
|
|
||||||
proto-reformat-full:
|
proto-reformat-full:
|
||||||
../autogenpb --proto signal.proto --format
|
../autogenpb --proto signal.proto --format --debug
|
||||||
|
|
||||||
proto-reformat-fruit:
|
proto-reformat-fruit:
|
||||||
../autogenpb --proto fruit.proto --format
|
../autogenpb --proto fruit.proto --format
|
||||||
|
|
|
@ -54,7 +54,6 @@ message Basket { // `autogenpb:nomutex`
|
||||||
repeated Pear pears = 5;
|
repeated Pear pears = 5;
|
||||||
repeated Apple stacks = 6;
|
repeated Apple stacks = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Fruit" must exist. you can put anything in it
|
// "Fruit" must exist. you can put anything in it
|
||||||
message Fruit {
|
message Fruit {
|
||||||
string brand = 1; // `autogenpb:unique` `autogenpb:sort`
|
string brand = 1; // `autogenpb:unique` `autogenpb:sort`
|
||||||
|
@ -67,7 +66,6 @@ message Fruit {
|
||||||
repeated Basket gifts = 8;
|
repeated Basket gifts = 8;
|
||||||
int64 price = 9; // `autogenpb:sort`
|
int64 price = 9; // `autogenpb:sort`
|
||||||
}
|
}
|
||||||
|
|
||||||
// "Fruits" MUST EXIST and start exactly this way
|
// "Fruits" MUST EXIST and start exactly this way
|
||||||
// It must be "Fruit" + 's' and must match the name of this file: "fruit.proto"
|
// It must be "Fruit" + 's' and must match the name of this file: "fruit.proto"
|
||||||
message Fruits { // `autogenpb:marshal` `autogenpb:mutex` `autogenpb:gui`
|
message Fruits { // `autogenpb:marshal` `autogenpb:mutex` `autogenpb:gui`
|
||||||
|
@ -77,3 +75,4 @@ message Fruits { // `autogenpb:marshal` `
|
||||||
int64 cost = 4; // you can add additional things here but the three lines above must conform to the standard above
|
int64 cost = 4; // you can add additional things here but the three lines above must conform to the standard above
|
||||||
map<string, string> junk = 5;
|
map<string, string> junk = 5;
|
||||||
}
|
}
|
||||||
|
// footer was empty
|
||||||
|
|
|
@ -18,6 +18,7 @@ import (
|
||||||
|
|
||||||
var allTheLines *LinesScanner
|
var allTheLines *LinesScanner
|
||||||
|
|
||||||
|
/*
|
||||||
type EnumMessage struct {
|
type EnumMessage struct {
|
||||||
msgPB *FormatMsg
|
msgPB *FormatMsg
|
||||||
all []Message
|
all []Message
|
||||||
|
@ -44,6 +45,7 @@ type Message interface {
|
||||||
load()
|
load()
|
||||||
addMsg(Message)
|
addMsg(Message)
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func protoReformatComments(filename string) error {
|
func protoReformatComments(filename string) error {
|
||||||
// read in the .proto file
|
// read in the .proto file
|
||||||
|
@ -137,6 +139,7 @@ func doParse(lines []string) *FormatMsg {
|
||||||
|
|
||||||
if strings.HasPrefix(line, "oneof ") {
|
if strings.HasPrefix(line, "oneof ") {
|
||||||
newmsg := basemsg.newOneofMessage(line)
|
newmsg := basemsg.newOneofMessage(line)
|
||||||
|
comments = strings.TrimSpace(comments)
|
||||||
newmsg.Notes = strings.Split(comments, "\n")
|
newmsg.Notes = strings.Split(comments, "\n")
|
||||||
comments = ""
|
comments = ""
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
|
@ -146,6 +149,7 @@ func doParse(lines []string) *FormatMsg {
|
||||||
|
|
||||||
if strings.HasPrefix(line, "enum ") {
|
if strings.HasPrefix(line, "enum ") {
|
||||||
newmsg := basemsg.newEnumMessage(line)
|
newmsg := basemsg.newEnumMessage(line)
|
||||||
|
comments = strings.TrimSpace(comments)
|
||||||
newmsg.Notes = strings.Split(comments, "\n")
|
newmsg.Notes = strings.Split(comments, "\n")
|
||||||
comments = ""
|
comments = ""
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
|
@ -157,6 +161,7 @@ func doParse(lines []string) *FormatMsg {
|
||||||
log.Info("got to message", line)
|
log.Info("got to message", line)
|
||||||
|
|
||||||
newmsg := basemsg.newStdMessage(line)
|
newmsg := basemsg.newStdMessage(line)
|
||||||
|
comments = strings.TrimSpace(comments)
|
||||||
newmsg.Notes = strings.Split(comments, "\n")
|
newmsg.Notes = strings.Split(comments, "\n")
|
||||||
comments = ""
|
comments = ""
|
||||||
newmsg.load()
|
newmsg.load()
|
||||||
|
@ -227,9 +232,11 @@ func (msgPB *FormatMsg) newEnumMessage(header string) *FormatMsg {
|
||||||
// func loadMsgDefinition(msg *StdMessage) {
|
// func loadMsgDefinition(msg *StdMessage) {
|
||||||
// func (newMsg *EnumMessage) load() {
|
// func (newMsg *EnumMessage) load() {
|
||||||
// func (msg *StdMessage) loadMsgDefinition(msg *StdMessage) {
|
// func (msg *StdMessage) loadMsgDefinition(msg *StdMessage) {
|
||||||
|
/*
|
||||||
func (msg *StdMessage) load() {
|
func (msg *StdMessage) load() {
|
||||||
msg.msgPB.load()
|
msg.msgPB.load()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
func (msg *FormatMsg) load() {
|
func (msg *FormatMsg) load() {
|
||||||
// fmtmsg := msg.msgPB
|
// fmtmsg := msg.msgPB
|
||||||
|
@ -416,13 +423,16 @@ func (all *FormatMsg) format() []string {
|
||||||
func formatMessage(curmsg *FormatMsg) []string {
|
func formatMessage(curmsg *FormatMsg) []string {
|
||||||
var newmsg []string
|
var newmsg []string
|
||||||
|
|
||||||
// print the Notes
|
// add the notes & comments before the header
|
||||||
for _, line := range curmsg.Notes {
|
newmsg = append(newmsg, strings.TrimSpace(strings.Join(curmsg.Notes, "\n")))
|
||||||
newmsg = append(newmsg, line)
|
|
||||||
}
|
|
||||||
|
|
||||||
if curmsg.Header != "" {
|
if curmsg.Header != "" {
|
||||||
line := fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
|
var line string
|
||||||
|
if argv.Debug {
|
||||||
|
line = fmt.Sprintf("%s%s // msg depth=%d", curmsg.padBase(), curmsg.Header, curmsg.Depth)
|
||||||
|
} else {
|
||||||
|
line = fmt.Sprintf("%s%s", curmsg.padBase(), curmsg.Header)
|
||||||
|
}
|
||||||
parts := strings.Fields(line)
|
parts := strings.Fields(line)
|
||||||
if len(parts) > 3 {
|
if len(parts) > 3 {
|
||||||
// hack to actually indent comments on the message line itself. you're welcome
|
// hack to actually indent comments on the message line itself. you're welcome
|
||||||
|
@ -430,10 +440,19 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
end := strings.Join(parts[3:], " ")
|
end := strings.Join(parts[3:], " ")
|
||||||
offset := int(curmsg.MaxVarname) + int(curmsg.MaxVartype) + 16 - len(start)
|
offset := int(curmsg.MaxVarname) + int(curmsg.MaxVartype) + 16 - len(start)
|
||||||
pad := fmt.Sprintf("%d", offset)
|
pad := fmt.Sprintf("%d", offset)
|
||||||
|
if argv.Debug {
|
||||||
hmm := "%s %" + pad + "s %s // depth=%d"
|
hmm := "%s %" + pad + "s %s // depth=%d"
|
||||||
line = fmt.Sprintf(hmm, start, " ", end, curmsg.Depth)
|
line = fmt.Sprintf(hmm, start, " ", end, curmsg.Depth)
|
||||||
} else {
|
} else {
|
||||||
|
hmm := "%s %" + pad + "s %s"
|
||||||
|
line = fmt.Sprintf(hmm, start, " ", end)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if argv.Debug {
|
||||||
line = fmt.Sprintf("%s // len(parts)=%d depth=%d", line, len(parts), curmsg.Depth)
|
line = fmt.Sprintf("%s // len(parts)=%d depth=%d", line, len(parts), curmsg.Depth)
|
||||||
|
} else {
|
||||||
|
// line = fmt.Sprintf("%s test", line)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
newmsg = append(newmsg, line) // " //header")
|
newmsg = append(newmsg, line) // " //header")
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue