commands

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package commands builds the Cobra command tree from an OpenAPI 3 spec. It handles tag-to-resource mapping, HTTP method-to-action verbs, parameter-to-flag mapping, and nested resource extraction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Spec   *openapi3.T
	Runner CLIRunner
}

Builder turns an OpenAPI 3 spec into a Cobra command tree grouped by tag, with one Cobra subcommand per operation.

func NewBuilder

func NewBuilder(spec *openapi3.T, runner CLIRunner) *Builder

NewBuilder constructs a Builder from a loaded spec and a CLIRunner.

func (*Builder) Build

func (b *Builder) Build() *cobra.Command

Build produces the root cobra.Command populated with all the dynamic command groups derived from the spec paths. Each tag becomes a subcommand group, with leaf commands for each operation.

type CLIRunner

type CLIRunner interface {
	RunOperation(cmd *cobra.Command, method, path string, op *openapi3.Operation, sf SpecFlags) error
}

CLIRunner is the dependency-injected execution surface for leaf commands. The CLI wiring provides a concrete implementation in internal/cli that calls the HTTP executor and output formatter.

type FlagDef

type FlagDef struct {
	Name        string
	Shorthand   string
	Description string
	Type        string // "string", "bool", "int", "stringArray"
	Required    bool
	IsBody      bool
	Default     any
}

FlagDef is a lightweight description of a Cobra flag produced from an OpenAPI 3 operation parameter. It is used by the builder to register flags on the leaf commands.

type PathArg

type PathArg struct {
	Name string
}

PathArg is a positional argument derived from a path parameter.

type SpecFlags

type SpecFlags struct {
	PathArgs   []PathArg
	QueryFlags []FlagDef
	BodyFlag   *FlagDef
}

SpecFlags bundles all flag/arg metadata extracted from an operation.

Jump to

Keyboard shortcuts

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