This repository was archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
66 lines (48 loc) · 1.22 KB
/
main.go
File metadata and controls
66 lines (48 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"encoding/json"
"fmt"
"go/parser"
"go/token"
"log"
"os"
"path"
)
func main() {
fileName := os.Getenv("GOFILE")
if fileName == "" {
log.Print("GOFILE cannot be blank")
}
if len(os.Args) != 2 {
log.Fatal("Must pass the desired output path as the only argument")
}
outPath := os.Args[1]
if _, err := os.Stat(outPath); os.IsNotExist(err) {
log.Printf("Creating output folder: %v", outPath)
err := os.Mkdir(outPath, os.ModePerm)
if err != nil {
log.Fatalf("Error creating folder: %v", err)
}
}
log.Printf("Generating docs data for %v", fileName)
fset := token.NewFileSet()
parsed, err := parser.ParseFile(fset, fileName, nil, parser.ParseComments)
if err != nil {
log.Printf("Error parsing file: %v", err)
}
doc, err := ParseFile(parsed)
if err != nil {
log.Fatalf("Error parsing file %v: %v", fileName, err)
}
// Format as JSON
b, err := json.MarshalIndent(doc, "", " ")
if err != nil {
log.Fatalf("Error generating JSON: %v", err)
}
outFile := path.Join(outPath, fmt.Sprintf("%v.json", doc.OvermindType))
err = os.WriteFile(outFile, b, 0644)
if err != nil {
log.Fatalf("Error writing file %v: %v", outFile, err)
}
log.Printf("JSON written: %v", outFile)
}