this repo has no description smallweb.run
smallweb
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 66 lines 1.2 kB view raw
1package cmd 2 3import ( 4 "fmt" 5 "strings" 6 7 "github.com/spf13/cobra" 8 "github.com/spf13/cobra/doc" 9) 10 11func NewCmdDocs() *cobra.Command { 12 cmd := &cobra.Command{ 13 Use: "docs", 14 Short: "Generate smallweb cli documentation", 15 Hidden: true, 16 RunE: func(cmd *cobra.Command, args []string) error { 17 doc, err := buildDoc(cmd.Root()) 18 if err != nil { 19 return fmt.Errorf("failed to generate docs: %w", err) 20 } 21 22 fmt.Println("# CLI Reference") 23 fmt.Println() 24 fmt.Println(doc) 25 fmt.Println() 26 fmt.Println("<!-- markdownlint-disable-file -->") 27 28 return nil 29 }, 30 } 31 return cmd 32} 33func buildDoc(command *cobra.Command) (string, error) { 34 var page strings.Builder 35 err := doc.GenMarkdown(command, &page) 36 if err != nil { 37 return "", err 38 } 39 40 out := strings.Builder{} 41 for _, line := range strings.Split(page.String(), "\n") { 42 if strings.Contains(line, "SEE ALSO") { 43 break 44 } 45 46 out.WriteString(line + "\n") 47 } 48 49 for _, child := range command.Commands() { 50 if child.Hidden { 51 continue 52 } 53 54 if child.Name() == "help" || child.Name() == "completion" { 55 continue 56 } 57 58 childPage, err := buildDoc(child) 59 if err != nil { 60 return "", err 61 } 62 out.WriteString(childPage) 63 } 64 65 return out.String(), nil 66}