cobra2snooty

package module
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2025 License: Apache-2.0 Imports: 13 Imported by: 5

README

cobra2snooty

CI

Generate Snooty docs for the entire command tree

This program can actually generate docs for the mongocli command in the MongoDB CLI project

package main

import (
	"log"
	"os"

	"github.com/mongodb/mongocli/internal/cli/root"
	"github.com/mongodb-labs/cobra2snooty"
)

func main() {
	var profile string
	const docsPermissions = 0766
	if err := os.MkdirAll("./docs/command", docsPermissions); err != nil {
		log.Fatal(err)
	}

	mongocli := root.Builder(&profile, []string{})

	if err := cobra2snooty.GenSnootyTree(mongocli, "./docs/command"); err != nil {
		log.Fatal(err)
	}
}

This will generate a whole series of files, one for each command in the tree, in the directory specified (in this case "./docs/command")

License

cobra2snooty is released under the Apache 2.0 license. See LICENSE

Documentation

Overview

Package cobra2snooty was mostly inspired by https://github.com/spf13/cobra/tree/master/doc but with some changes to match the expected formats and styles of our writers and tools.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingDescription = errors.New("missing description")
)

Functions

func DefaultExampleFormatter added in v0.19.0

func DefaultExampleFormatter(w io.Writer, cmd *cobra.Command)

func DefaultTimeGetter added in v0.19.0

func DefaultTimeGetter() time.Time

func FlagUsages

func FlagUsages(f *pflag.FlagSet) string

func GenDocs added in v0.2.0

func GenDocs(cmd *cobra.Command, w io.Writer, genDocOptions ...GenDocsOption) error

GenDocs creates snooty help output. Adapted from https://github.com/spf13/cobra/tree/master/doc to match MongoDB tooling and style.

func GenTreeDocs added in v0.2.0

func GenTreeDocs(cmd *cobra.Command, dir string, genDocOptions ...GenDocsOption) error

GenTreeDocs generates the docs for the full tree of commands.

func WithCustomExampleFormatter added in v0.19.0

func WithCustomExampleFormatter(customFormatter ExampleFormatter) func(options *GenDocsOptions)

func WithCustomTimeGetter added in v0.19.0

func WithCustomTimeGetter(customTimeGetter func() time.Time) func(options *GenDocsOptions)

Types

type ExampleFormatter added in v0.19.0

type ExampleFormatter func(w io.Writer, cmd *cobra.Command)

type GenDocsOption added in v0.19.0

type GenDocsOption = func(options *GenDocsOptions)

type GenDocsOptions added in v0.19.0

type GenDocsOptions struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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