MCPcopy Index your code
hub / github.com/coder/coder / main

Function main

scripts/clidocgen/main.go:81–201  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79}
80
81func main() {
82 prepareEnv()
83
84 workdir, err := os.Getwd()
85 if err != nil {
86 flog.Fatalf("getwd: %v", err)
87 }
88 root := (&cli.RootCmd{})
89
90 // wroteMap indexes file paths to commands.
91 wroteMap := make(map[string]*serpent.Command)
92
93 var (
94 docsDir = filepath.Join(workdir, "docs")
95 cliMarkdownDir = filepath.Join(docsDir, "reference/cli")
96 )
97
98 if d := os.Getenv("DOCS_DIR"); d != "" {
99 docsDir = d
100 cliMarkdownDir = filepath.Join(docsDir, "reference/cli")
101 }
102
103 cmd, err := root.Command(root.EnterpriseSubcommands())
104 if err != nil {
105 flog.Fatalf("creating command: %v", err)
106 }
107 err = genTree(
108 cliMarkdownDir,
109 cmd,
110 wroteMap,
111 )
112 if err != nil {
113 flog.Fatalf("generating markdowns: %v", err)
114 }
115
116 // Delete old files
117 err = filepath.Walk(cliMarkdownDir, func(path string, info os.FileInfo, err error) error {
118 if err != nil {
119 return err
120 }
121 if info.IsDir() {
122 return nil
123 }
124 _, ok := wroteMap[path]
125 if !ok {
126 flog.Infof("deleting old doc\t %v", path)
127 if err := os.Remove(path); err != nil {
128 return err
129 }
130 }
131 return nil
132 })
133 if err != nil {
134 flog.Fatalf("deleting old docs: %v", err)
135 }
136
137 err = deleteEmptyDirs(cliMarkdownDir)
138 if err != nil {

Callers

nothing calls this directly

Calls 12

FileFunction · 0.92
prepareEnvFunction · 0.85
genTreeFunction · 0.85
deleteEmptyDirsFunction · 0.85
fullNameFunction · 0.85
CommandMethod · 0.80
EnterpriseSubcommandsMethod · 0.80
InfofMethod · 0.80
RemoveMethod · 0.65
ReadFileMethod · 0.65
FatalfMethod · 0.45
UnmarshalMethod · 0.45

Tested by

no test coverage detected