MCPcopy
hub / github.com/kopia/kopia / generateCommands

Function generateCommands

tools/cli2md/cli2md.go:161–192  ·  view source on GitHub ↗
(app *kingpin.ApplicationModel, section string, weight int, advanced bool)

Source from the content-addressed store, hash-verified

159}
160
161func generateCommands(app *kingpin.ApplicationModel, section string, weight int, advanced bool) error {
162 dir := filepath.Join(*baseDir, section)
163
164 if err := os.MkdirAll(dir, dirMode); err != nil {
165 return errors.Wrapf(err, "error creating section directory for %v", section)
166 }
167
168 f, err := os.Create(filepath.Join(dir, "_index.md")) //nolint:gosec
169 if err != nil {
170 return errors.Wrap(err, "unable to create common flags file")
171 }
172 defer f.Close() //nolint:errcheck
173
174 title := section + " Commands"
175
176 //nolint:errcheck
177 fmt.Fprintf(f, `---
178title: %q
179linkTitle: %q
180weight: %v
181hide_summary: true
182no_list: true
183---
184`, title, title, weight)
185
186 flat := flattenCommands(app.Commands)
187 for _, c := range flat {
188 generateSubcommands(f, dir, c.Help, c.Commands, advanced)
189 }
190
191 return nil
192}
193
194func flattenCommands(cmds []*kingpin.CmdModel) []*kingpin.CmdModel {
195 var result []*kingpin.CmdModel

Callers 1

mainFunction · 0.85

Calls 4

flattenCommandsFunction · 0.85
generateSubcommandsFunction · 0.85
MkdirAllMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected