@@ -15,6 +15,7 @@ import (
15
15
16
16
var (
17
17
flagDoWrite = flag .Bool ("write" , false , "Write to the opened file" )
18
+ flagClean = flag .Bool ("clean" , false , "Removes the added documentation (use with -write)" )
18
19
flagLuaVersion = flag .String ("luaversion" , "5.1" , "Lua documentation version" )
19
20
// flagHelp = flag.Bool("help", false, "Show help")
20
21
// flagHelpShort = flag.Bool("h", false, "Show help")
@@ -27,7 +28,7 @@ func main() {
27
28
// return
28
29
// }
29
30
if len (os .Args ) < 2 {
30
- fmt .Printf ("Usage: %s [-write] [-luaversion <version | 5.1>] <go-file> " , os .Args [0 ])
31
+ fmt .Printf ("Usage: %s [-write] [-clean] [- luaversion <version | 5.1>] <go-file> " , os .Args [0 ])
31
32
os .Exit (1 )
32
33
}
33
34
@@ -40,31 +41,37 @@ func main() {
40
41
os .Exit (1 )
41
42
}
42
43
43
- // Fetch or load cached Lua documentation
44
- luadocs , err := getCachedLuaDocs ()
45
- if err != nil {
46
- fmt .Println ("Error fetching Lua documentation:" , err )
47
- os .Exit (1 )
48
- }
44
+ updatedCode := ""
45
+ if * flagClean {
46
+ updatedCode = removeOldDocumentation (string (goCode ))
47
+ } else {
49
48
50
- luaFuncs , err := parseLuaDocs (luadocs )
51
- if err != nil {
52
- fmt .Println ("Error parsing Lua documentation:" , err )
53
- os .Exit (1 )
54
- }
49
+ // Fetch or load cached Lua documentation
50
+ luadocs , err := getCachedLuaDocs ()
51
+ if err != nil {
52
+ fmt .Println ("Error fetching Lua documentation:" , err )
53
+ os .Exit (1 )
54
+ }
55
55
56
- // Add comments to the Go code
57
- annotatedCode := addDocumentation (string (goCode ), luaFuncs )
56
+ luaFuncs , err := parseLuaDocs (luadocs )
57
+ if err != nil {
58
+ fmt .Println ("Error parsing Lua documentation:" , err )
59
+ os .Exit (1 )
60
+ }
61
+
62
+ // Add comments to the Go code
63
+ updatedCode = addDocumentation (string (goCode ), luaFuncs )
64
+ }
58
65
59
66
if * flagDoWrite {
60
- err := os .WriteFile (goFile , []byte (annotatedCode ), 0644 )
67
+ err := os .WriteFile (goFile , []byte (updatedCode ), 0644 )
61
68
if err != nil {
62
69
fmt .Println ("Error writing annotated code to file:" , err )
63
70
os .Exit (1 )
64
71
}
65
72
fmt .Println ("Annotated code written back to" , goFile )
66
73
} else {
67
- fmt .Println (annotatedCode )
74
+ fmt .Println (updatedCode )
68
75
}
69
76
}
70
77
0 commit comments