MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / GenMDDoc

Function GenMDDoc

cmd/internal/commands/doc.go:70–100  ·  view source on GitHub ↗

GenMDDoc generates markdown documentation for the given root command.

(root *cobra.Command)

Source from the content-addressed store, hash-verified

68
69// GenMDDoc generates markdown documentation for the given root command.
70func GenMDDoc(root *cobra.Command) *cobra.Command {
71 cmd := &cobra.Command{
72 Use: "gen-md-doc",
73 Hidden: true,
74 Short: fmt.Sprintf("Generate markdown documentation for %s", root.Name()),
75 RunE: func(cmd *cobra.Command, args []string) error {
76 dir, _ := cmd.Flags().GetString("out")
77 if _, err := os.Stat(dir); os.IsNotExist(err) {
78 if err := os.MkdirAll(dir, 0o755); err != nil {
79 return err
80 }
81 }
82 disableAutoGenTag(root)
83 prepender := func(filename string) string {
84 name := filepath.Base(filename)
85 base := strings.TrimSuffix(name, path.Ext(name))
86 title := strings.Replace(base, "_", " ", -1)
87 fmt.Printf(`Write "%s" to %s`+"\n", title, filename)
88 return fmt.Sprintf(MDDocFrontmatterTemplate, title, base)
89 }
90
91 linkHandler := func(name string) string {
92 base := strings.TrimSuffix(name, path.Ext(name))
93 return fmt.Sprintf(`{{< relref "%s" >}}`, strings.ToLower(base))
94 }
95 return doc.GenMarkdownTreeCustom(root, dir, prepender, linkHandler)
96 },
97 }
98 cmd.Flags().StringP("out", "o", "doc", "output directory")
99 return cmd
100}
101
102type command struct {
103 Short string `json:"short,omitempty"`

Callers 2

root.goFile · 0.92
root.goFile · 0.92

Calls 4

disableAutoGenTagFunction · 0.85
FlagsMethod · 0.80
NameMethod · 0.65
PrintfMethod · 0.45

Tested by

no test coverage detected