From 06a26af5bad29df7faee018701c167fb1dad144e Mon Sep 17 00:00:00 2001 From: diamondburned Date: Fri, 8 Jan 2021 19:55:35 -0800 Subject: [PATCH] Slightly cleaner generation structure --- cmd/internal/cchat-empty-gen/main.go | 3 ++- cmd/internal/cchat-generator/main.go | 9 ++++++--- generator.go | 3 ++- repository/comment.go | 11 ++++++++++- repository/gob/repository.gob | Bin 38254 -> 38253 bytes utils/empty/generator.go | 3 --- 6 files changed, 20 insertions(+), 9 deletions(-) delete mode 100644 utils/empty/generator.go diff --git a/cmd/internal/cchat-empty-gen/main.go b/cmd/internal/cchat-empty-gen/main.go index 6e5f3ae..3ea0bb3 100644 --- a/cmd/internal/cchat-empty-gen/main.go +++ b/cmd/internal/cchat-empty-gen/main.go @@ -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) } diff --git a/cmd/internal/cchat-generator/main.go b/cmd/internal/cchat-generator/main.go index 97b4bed..d5fbfd4 100644 --- a/cmd/internal/cchat-generator/main.go +++ b/cmd/internal/cchat-generator/main.go @@ -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) } diff --git a/generator.go b/generator.go index d8e7899..69518d9 100644 --- a/generator.go +++ b/generator.go @@ -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 } diff --git a/repository/comment.go b/repository/comment.go index 6052bb4..4335e7a 100644 --- a/repository/comment.go +++ b/repository/comment.go @@ -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") diff --git a/repository/gob/repository.gob b/repository/gob/repository.gob index 833143d74d1f14fddc31b3f0cfba4d755d95734e..a404ff4fb9294e5a2fce518e754d933fe8c5c851 100644 GIT binary patch delta 85 zcmV-b0IL7)ssin*0^Lo(Lp1#tOV2slkE#vlQ5G6vvmv{6QJiD?*IS* diff --git a/utils/empty/generator.go b/utils/empty/generator.go deleted file mode 100644 index 68c0247..0000000 --- a/utils/empty/generator.go +++ /dev/null @@ -1,3 +0,0 @@ -package empty - -//go:generate go run ../../cmd/internal/cchat-empty-gen