Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package
v0.54.18 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package cli mounts an apisurface.Surface as cobra commands. Every command calls the product's HTTP API exactly as the OpenAPI contract describes it; products supply the base URL and authorization, embed their generated api-surface.json and call Mount from their root command.

Index

Constants

View Source
const (
	ExitFailure      = 1 // any other failure
	ExitInvalid      = 2 // invalid input or HTTP 400/422
	ExitUnauthorized = 3 // HTTP 401
	ExitDenied       = 4 // HTTP 402/403/429
	ExitNotFound     = 5 // HTTP 404
	ExitConflict     = 6 // HTTP 409
	ExitUnavailable  = 7 // HTTP 5xx or transport failure
	ExitConfirmation = 9 // confirmation required or declined
)

Exit codes returned through ExitError.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps an error returned by cobra's Execute to a process exit code.

func LoadSurface

func LoadSurface(data []byte) (*apisurface.Surface, error)

LoadSurface decodes an embedded api-surface.json.

func Mount

func Mount(root *cobra.Command, s *apisurface.Surface, cfg Config) error

Mount adds one command per surface operation under root, creating intermediate group commands, plus an agent-context command unless root already has one. It fails when a generated command collides with an existing command.

Types

type Config

type Config struct {
	// BaseURL returns the API origin, e.g. "https://api.kombify.io/v1/techstack".
	BaseURL func(ctx context.Context) (string, error)
	// ResolvePath optionally maps the contract path (parameters substituted)
	// to the path under BaseURL, e.g. to strip a prefix the edge re-adds.
	ResolvePath func(path string) string
	// HTTPClient defaults to http.DefaultClient.
	HTTPClient *http.Client
	// Authorize adds credentials to an outgoing request; nil sends none. It
	// is never called for --dry-run or refused confirmations.
	Authorize func(*http.Request) error
	// In, Out and Err default to the process streams.
	In       io.Reader
	Out, Err io.Writer
	// Interactive reports whether a human can answer a confirmation prompt;
	// nil means non-interactive, so confirmations fail closed.
	Interactive func() bool
}

Config binds the generated commands to a product runtime.

type ExitError

type ExitError struct {
	Code int
	Err  error
	// contains filtered or unexported fields
}

ExitError carries the process exit code for a failed command.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

Jump to

Keyboard shortcuts

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