Slightly cleaner generation structure

This commit is contained in:
diamondburned 2021-01-08 19:55:35 -08:00
parent 903fe9fbfd
commit 06a26af5ba
6 changed files with 20 additions and 9 deletions

View File

@ -5,6 +5,7 @@ import (
"log"
"os"
"path"
"path/filepath"
"sort"
"strings"
@ -74,7 +75,7 @@ func main() {
}
}
f, err := os.Create("empty.go")
f, err := os.Create(filepath.Join(os.Args[1], "empty.go"))
if err != nil {
log.Fatalln("Failed to create output file:", err)
}

View File

@ -21,8 +21,11 @@ func main() {
for pkgPath, pkg := range repository.Main {
g := generate(pkgPath, pkg)
var destDir = filepath.FromSlash(trimPrefix(repository.RootPath, pkgPath))
var destFle = filepath.Base(pkgPath)
destDir := filepath.Join(
os.Args[1],
filepath.FromSlash(trimPrefix(repository.RootPath, pkgPath)),
)
destFile := filepath.Base(pkgPath) + ".go"
// Guarantee that the directory exists.
if destDir != "" {
@ -31,7 +34,7 @@ func main() {
}
}
f, err := os.Create(filepath.Join(destDir, destFle+".go"))
f, err := os.Create(filepath.Join(destDir, destFile))
if err != nil {
log.Fatalln("Failed to create output file:", err)
}

View File

@ -1,6 +1,7 @@
package cchat
//go:generate go run ./cmd/internal/cchat-generator
//go:generate go run ./cmd/internal/cchat-generator ./
//go:generate go run ./cmd/internal/cchat-empty-gen ./utils/empty/
type authenticateError struct{ error }

View File

@ -31,6 +31,10 @@ func (c Comment) IsEmpty() bool {
// prefix each line with "// ". The ident argument controls the nested level. If
// less than or equal to zero, then it is changed to 1, which is the top level.
func (c Comment) GoString(ident int) string {
if c.Raw == "" {
return ""
}
if ident < 1 {
ident = 1
}
@ -40,7 +44,12 @@ func (c Comment) GoString(ident int) string {
var lines = strings.Split(c.WrapText(80-len("// ")-ident), "\n")
for i, line := range lines {
lines[i] = "// " + line
if line != "" {
line = "// " + line
} else {
line = "//"
}
lines[i] = line
}
return strings.Join(lines, "\n")

Binary file not shown.

View File

@ -1,3 +0,0 @@
package empty
//go:generate go run ../../cmd/internal/cchat-empty-gen