ocobra

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package ocobra provides the ability to create OpenCLI documents from existing Cobra CLIs.

It attaches a hidden subcommand to an existing Cobra root command that, when invoked, walks the entire command tree and emits a valid OpenCLI spec document.

Typical usage:

var rootCmd = &cobra.Command{Use: "myapp", Short: "An awesome CLI"}
opencobra.FromCommand(rootCmd)
rootCmd.Execute()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromCommand

func FromCommand(rootCmd *cobra.Command, opts ...Option)

FromCommand attaches a hidden "__opencli" subcommand to rootCmd. Running that subcommand walks the Cobra command tree and writes an OpenCLI spec document to the configured output (default: stdout).

func GenerateDocument

func GenerateDocument(rootCmd *cobra.Command, opts ...Option) *spec.Document

GenerateDocument walks a Cobra command tree and returns the corresponding OpenCLI spec.Document. This is exported so callers can inspect or modify the document before serializing it themselves.

func GetBinaryName

func GetBinaryName(rootCmd *cobra.Command) string

GetBinaryName extracts the binary name from a root command's Use field. This is a convenience helper for constructing spec.Info.

func ParseUse

func ParseUse(use string) []spec.ArgumentItem

ParseUse parses a Cobra Use string and returns the positional arguments found.

Types

type Option

type Option func(*config)

Option is a functional option for FromCommand.

func WithFormat

func WithFormat(f codec.Format) Option

WithFormat sets the output format ("yaml" or "json"). Defaults to YAML.

func WithGlobalFlags

func WithGlobalFlags(flags []spec.FlagItem) Option

WithGlobalFlags sets flags that apply globally (e.g. --help, --version).

func WithInfo

func WithInfo(info *spec.Info) Option

WithInfo sets the top-level spec.Info block. If omitted, only binary name (derived from root.Use) will be populated.

func WithInstallMethods

func WithInstallMethods(install []spec.InstallMethod) Option

WithInstallMethods sets the install methods list.

func WithOutput

func WithOutput(w io.Writer) Option

WithOutput sets the io.Writer for the generated spec. Defaults to os.Stdout if omitted.

Jump to

Keyboard shortcuts

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