generateCommandDocs recursively generates documentation for a command and its subcommands.
(cmd *cobra.Command, builder *strings.Builder, currentDepth int)
| 76 | |
| 77 | // generateCommandDocs recursively generates documentation for a command and its subcommands. |
| 78 | func generateCommandDocs(cmd *cobra.Command, builder *strings.Builder, currentDepth int) { |
| 79 | var cmdBuffer strings.Builder |
| 80 | // Generate base documentation |
| 81 | if err := doc.GenMarkdown(cmd, &cmdBuffer); err != nil { |
| 82 | log.Fatal(fmt.Errorf("failed to generate documentation: %w", err)) |
| 83 | } |
| 84 | processed := processCommand(cmdBuffer.String(), currentDepth) |
| 85 | builder.WriteString(processed) |
| 86 | |
| 87 | // Recursively process subcommands with increased depth |
| 88 | for _, subCmd := range cmd.Commands() { |
| 89 | if !subCmd.Hidden && !isPluginCommand(subCmd) { |
| 90 | generateCommandDocs(subCmd, builder, currentDepth+1) |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | // processCommand processes the command documentation, filtering out unnecessary sections and formatting headers. |
| 96 | func processCommand(content string, depth int) string { |
no test coverage detected