Skip to content

Commit

Permalink
fix: generate long desc and examples for root command
Browse files Browse the repository at this point in the history
Signed-off-by: David Karlsson <[email protected]>
  • Loading branch information
dvdksn committed Apr 12, 2024
1 parent 27c3157 commit ab5ac4f
Showing 1 changed file with 19 additions and 23 deletions.
42 changes: 19 additions & 23 deletions clidocstool.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,33 +88,29 @@ func (c *Client) GenAllTree() error {
}

// loadLongDescription gets long descriptions and examples from markdown.
func (c *Client) loadLongDescription(parentCmd *cobra.Command, generator string) error {
for _, cmd := range parentCmd.Commands() {
if cmd.HasSubCommands() {
if err := c.loadLongDescription(cmd, generator); err != nil {
func (c *Client) loadLongDescription(cmd *cobra.Command, generator string) error {
if cmd.HasSubCommands() {
for _, sub := range cmd.Commands() {
if err := c.loadLongDescription(sub, generator); err != nil {
return err
}
}
name := cmd.CommandPath()
if i := strings.Index(name, " "); i >= 0 {
// remove root command / binary name
name = name[i+1:]
}
if name == "" {
continue
}
mdFile := strings.ReplaceAll(name, " ", "_") + ".md"
sourcePath := filepath.Join(c.source, mdFile)
content, err := os.ReadFile(sourcePath)
if os.IsNotExist(err) {
log.Printf("WARN: %s does not exist, skipping Markdown examples for %s docs\n", mdFile, generator)
continue
}
if err != nil {
return err
}
applyDescriptionAndExamples(cmd, string(content))
}
name := cmd.CommandPath()
if i := strings.Index(name, " "); i >= 0 {
// remove root command / binary name
name = name[i+1:]
}
mdFile := strings.ReplaceAll(name, " ", "_") + ".md"
sourcePath := filepath.Join(c.source, mdFile)
content, err := os.ReadFile(sourcePath)
if os.IsNotExist(err) {
log.Printf("WARN: %s does not exist, skipping Markdown examples for %s docs\n", mdFile, generator)
}
if err != nil {
return err
}
applyDescriptionAndExamples(cmd, string(content))
return nil
}

Expand Down

0 comments on commit ab5ac4f

Please sign in to comment.