gen

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package gen contains funtions to generate documentation and framework-specific boilerplate code from a valid OpenCLI specification document.

Given a spec.Document, gen can produce:

  1. Documentation — Call Docs to generate Markdown (or other formats) suitable for publishing CLI reference documentation.

  2. CLI code — Call CLI with a target CLIFramework to generate boilerplate code for one of the supported frameworks:

    CobraFramework — github.com/spf13/cobra (Go) • UrfaveCliFramework — github.com/urfave/cli/v3 (Go) • YargsFramework — yargs (Node.js)

Generated code is returned as a map of relative file paths to their contents, ready to be written to disk. All files belong to a single gencli package so no cross-package import paths are required.

Both CLI and Docs support functional options for configuring output format, framework, badges, footers, and other generation parameters.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLI

func CLI(doc *spec.Document, options ...GenCLIOption) (map[string][]byte, error)

CLI generates framework-specific boilerplate code from an OpenCLI document. It returns a map of relative file paths (under gencli/) to their generated content, ready to be written to disk. All files belong to the gencli package.

Example:

files, err := gen.CLI(doc, gen.GenCLIWithFramework(gen.YargsFramework))
if err != nil { return err }
for path, content := range files {
  fs.WriteFile(path, content, 0644)
}

func Docs

func Docs(doc *spec.Document, options ...GenDocsOption) ([]byte, error)

Docs generates documentation based on the given OpenCLI document

Types

type CLIFramework

type CLIFramework string

CLIFramework is the target framework for CLI code generation.

Use with GenCLIWithFramework to select a supported framework:

files, err := gen.CLI(doc, gen.GenCLIWithFramework(gen.CobraFramework))
const (
	// CobraFramework generates code for the github.com/spf13/cobra framework.
	CobraFramework CLIFramework = "COBRA"
	// YargsFramework generates code for the yargs Node.js framework.
	YargsFramework CLIFramework = "YARGS"
	// UrfaveCliFramework generates code for the github.com/urfave/cli/v3 framework.
	UrfaveCliFramework CLIFramework = "URFAVECLI"
)

func (CLIFramework) IsValid

func (f CLIFramework) IsValid() bool

IsValid reports whether f is a supported CLIFramework.

type DocFormat

type DocFormat string

DocFormat is the output format for generated documentation.

const (
	Markdown   DocFormat = "MARKDOWN"
	HTML_PAGE  DocFormat = "HTML_PAGE"
	HTML_EMBED DocFormat = "HTML_EMBED"
	ManPage    DocFormat = "MAN"
)

func (DocFormat) IsValid

func (f DocFormat) IsValid() bool

type GenCLIOption

type GenCLIOption func(*genCLIOptions)

GenCLIOption is a functional option to configure the CLI function.

func GenCLIWithFramework

func GenCLIWithFramework(f CLIFramework) GenCLIOption

GenCLIWithFramework sets the target CLI framework.

type GenDocsOption

type GenDocsOption func(*genDocsOptions)

GenDocsOption is a functional option to configure the GenDocs function

func DocsWithFormat

func DocsWithFormat(format DocFormat) GenDocsOption

DocsWithFormat sets the desired output format of the documentation.

func DocsWithoutBadge

func DocsWithoutBadge() GenDocsOption

DocsWithoutBadge option will remove shields.io badge that indicates compliance with the OpenCLI Spec prepended to markdown documents by default.

func DocsWithoutFooter

func DocsWithoutFooter() GenDocsOption

DocsWithoutFooter option will remove the `generated by OpenCLI` footer appended to the documents by default.

Jump to

Keyboard shortcuts

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