Skip to content

Commit adf75cb

Browse files
committed
fix: generate long desc and examples for root command
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 27c3157 commit adf75cb

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

clidocstool.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,33 @@ func (c *Client) GenAllTree() error {
8888
}
8989

9090
// loadLongDescription gets long descriptions and examples from markdown.
91-
func (c *Client) loadLongDescription(parentCmd *cobra.Command, generator string) error {
92-
for _, cmd := range parentCmd.Commands() {
93-
if cmd.HasSubCommands() {
94-
if err := c.loadLongDescription(cmd, generator); err != nil {
91+
func (c *Client) loadLongDescription(cmd *cobra.Command, generator string) error {
92+
if cmd.HasSubCommands() {
93+
for _, sub := range cmd.Commands() {
94+
if err := c.loadLongDescription(sub, generator); err != nil {
9595
return err
9696
}
9797
}
98-
name := cmd.CommandPath()
99-
if i := strings.Index(name, " "); i >= 0 {
100-
// remove root command / binary name
101-
name = name[i+1:]
102-
}
103-
if name == "" {
104-
continue
105-
}
106-
mdFile := strings.ReplaceAll(name, " ", "_") + ".md"
107-
sourcePath := filepath.Join(c.source, mdFile)
108-
content, err := os.ReadFile(sourcePath)
109-
if os.IsNotExist(err) {
110-
log.Printf("WARN: %s does not exist, skipping Markdown examples for %s docs\n", mdFile, generator)
111-
continue
112-
}
113-
if err != nil {
114-
return err
115-
}
116-
applyDescriptionAndExamples(cmd, string(content))
11798
}
99+
name := cmd.CommandPath()
100+
if i := strings.Index(name, " "); i >= 0 {
101+
// remove root command / binary name
102+
name = name[i+1:]
103+
}
104+
if name == "" {
105+
return nil
106+
}
107+
mdFile := strings.ReplaceAll(name, " ", "_") + ".md"
108+
sourcePath := filepath.Join(c.source, mdFile)
109+
content, err := os.ReadFile(sourcePath)
110+
if os.IsNotExist(err) {
111+
log.Printf("WARN: %s does not exist, skipping Markdown examples for %s docs\n", mdFile, generator)
112+
return nil
113+
}
114+
if err != nil {
115+
return err
116+
}
117+
applyDescriptionAndExamples(cmd, string(content))
118118
return nil
119119
}
120120

0 commit comments

Comments
 (0)