| 69 | } |
| 70 | |
| 71 | func loadLongDescription(parentCommand *cobra.Command, path string) error { |
| 72 | for _, cmd := range parentCommand.Commands() { |
| 73 | cmd.DisableFlagsInUseLine = true |
| 74 | if cmd.Name() == "" { |
| 75 | continue |
| 76 | } |
| 77 | fullpath := filepath.Join(path, cmd.Name()+".md") |
| 78 | |
| 79 | if cmd.HasSubCommands() { |
| 80 | if err := loadLongDescription(cmd, filepath.Join(path, cmd.Name())); err != nil { |
| 81 | return err |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if _, err := os.Stat(fullpath); err != nil { |
| 86 | log.Printf("WARN: %s does not exist, skipping\n", fullpath) |
| 87 | continue |
| 88 | } |
| 89 | |
| 90 | log.Printf("INFO: %s found\n", fullpath) |
| 91 | content, err := os.ReadFile(fullpath) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | cmd.Long = string(content) |
| 96 | |
| 97 | fullpath = filepath.Join(path, cmd.Name()+"-example.md") |
| 98 | if _, err := os.Stat(fullpath); err != nil { |
| 99 | continue |
| 100 | } |
| 101 | |
| 102 | content, err = os.ReadFile(fullpath) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | cmd.Example = string(content) |
| 107 | } |
| 108 | return nil |
| 109 | } |
| 110 | |
| 111 | func run() error { |
| 112 | opts := &options{} |