docs

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 11 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CobraDocsCmd = &cobra.Command{
	Use:    "docs",
	Short:  "Generate docs",
	Long:   `Generate documentation markdown files from the source code.`,
	Hidden: true,
	Run: func(cmd *cobra.Command, args []string) {

		outputDir, _ := cmd.Flags().GetString("output-dir")
		identity := func(s string) string { return s }
		emptyStr := func(s string) string {

			isRootCommand := strings.HasSuffix(s, fmt.Sprintf("%c_index.md", os.PathSeparator))

			titleCaser := cases.Title(language.English)
			title := strings.TrimSuffix(strings.ReplaceAll(filepath.Base(s), "_", " "), markdownExtension)

			var prepend string
			if isRootCommand {
				commandNameTitle := titleCaser.String(cmd.Root().Name())
				prepend = fmt.Sprintf("---\ntitle: %s CLI\ndescription: %s CLI Reference\nno_list: true\nweight: 1\n---\n", commandNameTitle, commandNameTitle)

			} else {
				title = strings.TrimSpace(strings.TrimPrefix(title, cmd.Root().Name()))
				args := strings.Split(title, " ")
				currentCmd, _, err := cmd.Root().Find(args)
				if err != nil {
					fmt.Println("error getting command", err)
				}
				title = titleCaser.String(title)
				prepend = fmt.Sprintf("---\ntitle: %s\ndescription: %s\n---\n\n", title, currentCmd.Short)
			}

			return prepend
		}

		err := GenMarkdownTreeCustom(cmd.Root(), outputDir, emptyStr, identity)
		if err != nil {
			fmt.Printf("error generating docs err=%s", err)
		}
	},
}

CobraDocsCmd represents the docs command

Functions

func GenMarkdownCustom added in v1.0.1

func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error

GenMarkdownCustom creates custom markdown output.

func GenMarkdownTreeCustom added in v1.0.1

func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error

GenMarkdownTreeCustom is the same as GenMarkdownTree, but with custom filePrepender and linkHandler.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL