@@ -15,6 +15,7 @@ import (
1515
1616var (
1717 flagDoWrite = flag .Bool ("write" , false , "Write to the opened file" )
18+ flagClean = flag .Bool ("clean" , false , "Removes the added documentation (use with -write)" )
1819 flagLuaVersion = flag .String ("luaversion" , "5.1" , "Lua documentation version" )
1920 // flagHelp = flag.Bool("help", false, "Show help")
2021 // flagHelpShort = flag.Bool("h", false, "Show help")
@@ -27,7 +28,7 @@ func main() {
2728 // return
2829 // }
2930 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 ])
3132 os .Exit (1 )
3233 }
3334
@@ -40,31 +41,37 @@ func main() {
4041 os .Exit (1 )
4142 }
4243
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 {
4948
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+ }
5555
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+ }
5865
5966 if * flagDoWrite {
60- err := os .WriteFile (goFile , []byte (annotatedCode ), 0644 )
67+ err := os .WriteFile (goFile , []byte (updatedCode ), 0644 )
6168 if err != nil {
6269 fmt .Println ("Error writing annotated code to file:" , err )
6370 os .Exit (1 )
6471 }
6572 fmt .Println ("Annotated code written back to" , goFile )
6673 } else {
67- fmt .Println (annotatedCode )
74+ fmt .Println (updatedCode )
6875 }
6976}
7077
0 commit comments