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 ¶
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 ¶
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 ¶
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 ¶
WithFormat sets the output format ("yaml" or "json"). Defaults to YAML.
func WithGlobalFlags ¶
WithGlobalFlags sets flags that apply globally (e.g. --help, --version).
func WithInfo ¶
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 ¶
WithOutput sets the io.Writer for the generated spec. Defaults to os.Stdout if omitted.