MCPcopy
hub / github.com/kopia/kopia / generateSubcommands

Function generateSubcommands

tools/cli2md/cli2md.go:247–269  ·  view source on GitHub ↗
(w io.Writer, dir, sectionTitle string, cmds []*kingpin.CmdModel, advanced bool)

Source from the content-addressed store, hash-verified

245}
246
247func generateSubcommands(w io.Writer, dir, sectionTitle string, cmds []*kingpin.CmdModel, advanced bool) {
248 cmds = append([]*kingpin.CmdModel(nil), cmds...)
249
250 first := true
251
252 for _, c := range cmds {
253 if c.Hidden != advanced {
254 continue
255 }
256
257 if first {
258 fmt.Fprintf(w, "\n### %v\n\n", strings.TrimSuffix(sectionTitle, ".")) //nolint:errcheck
259
260 first = false
261 }
262
263 subcommandSlug := strings.ReplaceAll(c.FullCommand, " ", "-")
264 helpSummary := strings.SplitN(c.Help, "\n", 2)[0] //nolint:mnd
265 helpSummary = strings.TrimSuffix(helpSummary, ".")
266 fmt.Fprintf(w, "* [`%v`](%v) - %v\n", c.FullCommand, subcommandSlug+"/", helpSummary) //nolint:errcheck
267 generateSubcommandPage(filepath.Join(dir, subcommandSlug+".md"), c)
268 }
269}
270
271func generateSubcommandPage(fname string, cmd *kingpin.CmdModel) {
272 f, err := os.Create(fname) //nolint:gosec

Callers 1

generateCommandsFunction · 0.85

Calls 1

generateSubcommandPageFunction · 0.85

Tested by

no test coverage detected