|
|
@ -54,10 +54,12 @@ func GoFormatApi(c *cli.Context) error {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
be.Add(err)
|
|
|
|
be.Add(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if be.NotNil() {
|
|
|
|
if be.NotNil() {
|
|
|
|
scanner.PrintError(os.Stderr, be.Err())
|
|
|
|
scanner.PrintError(os.Stderr, be.Err())
|
|
|
|
os.Exit(1)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return be.Err()
|
|
|
|
return be.Err()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -73,10 +75,7 @@ func ApiFormatByStdin() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
_, err = fmt.Print(result)
|
|
|
|
_, err = fmt.Print(result)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func ApiFormatByPath(apiFilePath string) error {
|
|
|
|
func ApiFormatByPath(apiFilePath string) error {
|
|
|
@ -90,10 +89,12 @@ func ApiFormatByPath(apiFilePath string) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := ioutil.WriteFile(apiFilePath, []byte(result), os.ModePerm); err != nil {
|
|
|
|
_, err = parser.ParseContent(result)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
|
|
return ioutil.WriteFile(apiFilePath, []byte(result), os.ModePerm)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func apiFormat(data string) (string, error) {
|
|
|
|
func apiFormat(data string) (string, error) {
|
|
|
@ -150,6 +151,7 @@ func apiFormat(data string) (string, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
preLine = line
|
|
|
|
preLine = line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return strings.TrimSpace(builder.String()), nil
|
|
|
|
return strings.TrimSpace(builder.String()), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -178,9 +180,9 @@ func formatGoTypeDef(line string, scanner *bufio.Scanner, builder *strings.Build
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true, nil
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return false, nil
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -212,5 +214,6 @@ func mayInsertStructKeyword(line string, token *int) string {
|
|
|
|
if strings.Contains(noCommentLine, "`") {
|
|
|
|
if strings.Contains(noCommentLine, "`") {
|
|
|
|
return util.UpperFirst(strings.TrimSpace(line))
|
|
|
|
return util.UpperFirst(strings.TrimSpace(line))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return line
|
|
|
|
return line
|
|
|
|
}
|
|
|
|
}
|
|
|
|