MCPcopy Create free account
hub / github.com/jetify-com/devbox / genDocsCmd

Function genDocsCmd

internal/boxcli/gen-docs.go:17–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func genDocsCmd() *cobra.Command {
18 genDocsCmd := &cobra.Command{
19 Use: "gen-docs <path>",
20 Short: "[Internal] Generate documentation for the CLI",
21 Long: "[Internal] Generates the documentation for the CLI's Cobra commands. " +
22 "Docs are placed in the directory specified by <path>.",
23 Hidden: true,
24 Args: cobra.ExactArgs(1),
25 RunE: func(cmd *cobra.Command, args []string) error {
26 wd, err := os.Getwd()
27 if err != nil {
28 return errors.WithStack(err)
29 }
30 docsPath := filepath.Join(wd, args[0] /* relative path */)
31
32 // We clear out the existing directory so that the doc-pages for
33 // commands that have been deleted in the CLI will also be removed
34 // after we re-generate the docs below
35 if err := fileutil.ClearDir(docsPath); err != nil {
36 return err
37 }
38
39 rootCmd := cmd
40 for rootCmd.HasParent() {
41 rootCmd = rootCmd.Parent()
42 }
43
44 // Removes the line in the generated docs of the form:
45 // ###### Auto generated by spf13/cobra on 18-Jul-2022
46 rootCmd.DisableAutoGenTag = true
47
48 return errors.WithStack(doc.GenMarkdownTree(rootCmd, docsPath))
49 },
50 }
51
52 return genDocsCmd
53}

Callers 1

RootCmdFunction · 0.85

Calls 1

ClearDirFunction · 0.92

Tested by

no test coverage detected