(root *cobra.Command)
| 85 | } |
| 86 | |
| 87 | func addCommandMetadata(root *cobra.Command) error { |
| 88 | return walkCommands(root, func(command *cobra.Command) error { |
| 89 | path := filepath.Join(outputDir, strings.ReplaceAll(command.CommandPath(), " ", "_")+".md") |
| 90 | contents, err := os.ReadFile(path) |
| 91 | if err != nil { |
| 92 | return fmt.Errorf("read generated doc %s: %w", path, err) |
| 93 | } |
| 94 | |
| 95 | updated := insertMetadataSection(contents, commandMetadataSection(command)) |
| 96 | if err := os.WriteFile(path, updated, 0o644); err != nil { |
| 97 | return fmt.Errorf("write generated doc %s: %w", path, err) |
| 98 | } |
| 99 | return nil |
| 100 | }) |
| 101 | } |
| 102 | |
| 103 | func walkCommands(command *cobra.Command, fn func(*cobra.Command) error) error { |
| 104 | if !command.IsAvailableCommand() || command.IsAdditionalHelpTopicCommand() { |
no test coverage detected