bindgen

package
v0.1.0-dev.20260222175125 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package bindgen provides tools for generating Starlark bindings from CLI metadata.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoType

func GoType(t string) string

GoType returns the Go type for a flag/arg type.

func SaveYAML

func SaveYAML(def *BindingDef, path string) error

SaveYAML saves a binding definition to a YAML file.

func StarlarkType

func StarlarkType(t string) string

StarlarkType returns the Starlark type annotation.

Types

type Arg

type Arg struct {
	Name        string `yaml:"name"`
	Type        string `yaml:"type"` // string, int, bool, string_list
	Required    bool   `yaml:"required"`
	Position    int    `yaml:"position"` // 0-indexed
	Description string `yaml:"description"`
}

Arg defines a positional argument.

type BindingDef

type BindingDef struct {
	Name        string              `yaml:"name"`        // e.g., "docker"
	Description string              `yaml:"description"` // Brief description
	Commands    map[string]*Command `yaml:"commands"`    // Subcommands/methods
}

BindingDef defines a CLI tool's Starlark binding.

func LoadYAML

func LoadYAML(path string) (*BindingDef, error)

LoadYAML loads a binding definition from a YAML file.

func Merge

func Merge(base, override *BindingDef) *BindingDef

Merge combines two binding definitions, with override taking precedence.

type Command

type Command struct {
	Name        string  `yaml:"-"`           // Populated from map key
	Description string  `yaml:"description"` // From --help or manual
	Args        []*Arg  `yaml:"args"`        // Positional arguments
	Flags       []*Flag `yaml:"flags"`       // Named flags
	Returns     *Return `yaml:"returns"`     // Return type specification
}

Command defines a single CLI command or subcommand.

type Flag

type Flag struct {
	Name        string   `yaml:"name"`    // Long name without --
	Short       string   `yaml:"short"`   // Single char without -
	Type        string   `yaml:"type"`    // string, int, bool, string_list, string_map
	Default     string   `yaml:"default"` // Default value as string
	Description string   `yaml:"description"`
	Values      []string `yaml:"values"` // Enum values if applicable
}

Flag defines a named flag/option.

type GoGenerator

type GoGenerator struct{}

GoGenerator produces Go source code for Starlark bindings.

func NewGoGenerator

func NewGoGenerator() *GoGenerator

NewGoGenerator creates a new Go code generator.

func (*GoGenerator) Generate

func (g *GoGenerator) Generate(def *BindingDef) (string, error)

Generate produces Go source code for a binding definition.

type HelpParser

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

HelpParser extracts binding metadata from CLI --help output.

func NewHelpParser

func NewHelpParser(command string) *HelpParser

NewHelpParser creates a parser for the given command.

func (*HelpParser) ListSubcommands

func (p *HelpParser) ListSubcommands() ([]string, error)

ListSubcommands attempts to extract subcommand names from help.

func (*HelpParser) Parse

func (p *HelpParser) Parse(subcommand string) (*Command, error)

Parse runs --help and extracts a Command definition.

type Return

type Return struct {
	Type   string   `yaml:"type"`   // result, string, bool, list, dict
	Fields []string `yaml:"fields"` // For result type: ok, stdout, stderr, code
	Parse  string   `yaml:"parse"`  // none, json, lines
}

Return defines what a command returns.

type StubGenerator

type StubGenerator struct{}

StubGenerator produces Starlark stub code for IDE completion.

func NewStubGenerator

func NewStubGenerator() *StubGenerator

NewStubGenerator creates a new Starlark stub generator.

func (*StubGenerator) Generate

func (g *StubGenerator) Generate(def *BindingDef) (string, error)

Generate produces Starlark stub code for a binding definition.

Directories

Path Synopsis
Package cobra extracts command metadata from Go source files using Cobra.
Package cobra extracts command metadata from Go source files using Cobra.

Jump to

Keyboard shortcuts

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