catalog

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package catalog holds the pre-parsed operation index that cchp ships inside the binary. It is generated by cmd/cchp-gen from the pinned upstream spec, spec/cli-overlay.yaml and spec/operation-policy.yaml, so discovery, help and policy checks work offline and start fast.

Index

Constants

View Source
const (
	StatusAvailable   = "available"
	StatusExcluded    = "excluded"
	StatusUnsupported = "unsupported"
)

Coverage outcomes for an upstream operation.

View Source
const (
	RiskRead        = "read"
	RiskWrite       = "write"
	RiskDestructive = "destructive"
)

Risk classes from spec/operation-policy.yaml.

View Source
const (
	ResponseJSON   = "json"
	ResponseStream = "stream"
	ResponseBinary = "binary"
	ResponseEmpty  = "empty"
)

Response kinds decide how cchp renders a successful response.

Variables

This section is empty.

Functions

func DecodeGzipJSON

func DecodeGzipJSON(data []byte, v any) error

DecodeGzipJSON decompresses data and decodes the JSON inside into v.

func Kebab added in v0.1.3

func Kebab(s string) string

Kebab turns an operationId such as listOrgProviders into list-org-providers.

Types

type Body

type Body struct {
	ContentType string   `json:"content_type"`
	Required    bool     `json:"required"`
	Kind        string   `json:"kind"` // json, multipart, binary
	FileFields  []string `json:"file_fields,omitempty"`
}

Body describes the request body.

type Catalog

type Catalog struct {
	Source     Source       `json:"source"`
	Groups     []Group      `json:"groups"`
	Operations []*Operation `json:"operations"`
	// contains filtered or unexported fields
}

Catalog is the whole generated index.

func DecodeGzip

func DecodeGzip(data []byte) (*Catalog, error)

DecodeGzip parses the gzip-compressed catalog JSON produced by the generator.

func (*Catalog) Available

func (c *Catalog) Available() []*Operation

Available returns the operations the CLI can call, in catalog order.

func (*Catalog) Get

func (c *Catalog) Get(id string) (*Operation, bool)

Get returns an operation by operationId.

func (*Catalog) Group

func (c *Catalog) Group(name string) (Group, bool)

Group returns a group by name.

func (*Catalog) InGroup

func (c *Catalog) InGroup(group string) []*Operation

InGroup returns the available operations of one group, sorted by name.

func (*Catalog) Search

func (c *Catalog) Search(query string, includeAll bool) []*Operation

Search ranks operations by how well they match every word of the query; an operation that misses a word is left out. Unavailable operations are included only when includeAll is set.

Among equal matches a list comes first, because a search that names a thing without saying what to do with it is looking for the list of that thing; then the command whose path holds more of the words exactly as typed; then the command with the shorter name.

type Group

type Group struct {
	Name    string `json:"name"`
	Title   string `json:"title"`
	Summary string `json:"summary"`
}

Group is a human command group such as "providers".

type Operation

type Operation struct {
	ID          string   `json:"id"`
	Method      string   `json:"method"`
	Path        string   `json:"path"`
	Group       string   `json:"group"`
	Name        string   `json:"name"`
	Aliases     []string `json:"aliases,omitempty"`
	Summary     string   `json:"summary"`
	Status      string   `json:"status"`
	Reason      string   `json:"reason,omitempty"`
	Public      bool     `json:"public,omitempty"`
	Params      []Param  `json:"params,omitempty"`
	Body        *Body    `json:"body,omitempty"`
	Response    Response `json:"response"`
	OrgHeader   bool     `json:"org_header,omitempty"`
	Idempotency bool     `json:"idempotency,omitempty"`
	Policy      Policy   `json:"policy"`
}

Operation is one upstream OpenAPI operation as cchp sees it.

func (*Operation) Command

func (op *Operation) Command() string

Command is the human command path, for example "providers list".

func (*Operation) Param

func (op *Operation) Param(flag string) (Param, bool)

Param returns the parameter with the given flag name.

type OperationSchemas

type OperationSchemas struct {
	Body     json.RawMessage `json:"body,omitempty"`
	Response json.RawMessage `json:"response,omitempty"`
}

OperationSchemas holds the bundled JSON Schemas of one operation.

type Pagination

type Pagination struct {
	Style      string `json:"style" yaml:"style"` // cursor or page
	Param      string `json:"param" yaml:"param"`
	LimitParam string `json:"limit_param,omitempty" yaml:"limit_param"`
	Next       string `json:"next,omitempty" yaml:"next"`
	HasMore    string `json:"has_more,omitempty" yaml:"has_more"`
	Items      string `json:"items" yaml:"items"`
	Total      string `json:"total,omitempty" yaml:"total"`
}

Pagination tells cchp how to walk an operation's pages.

type Param

type Param struct {
	Name        string   `json:"name"`
	In          string   `json:"in"`
	Flag        string   `json:"flag"`
	Type        string   `json:"type"`
	ItemType    string   `json:"item_type,omitempty"`
	Required    bool     `json:"required,omitempty"`
	Enum        []string `json:"enum,omitempty"`
	Default     any      `json:"default,omitempty"`
	Description string   `json:"description,omitempty"`
}

Param is one path, query or header parameter the CLI exposes.

type Policy

type Policy struct {
	Risk         string      `json:"risk"`
	Classified   bool        `json:"classified"`
	Retry        bool        `json:"retry"`
	Permission   string      `json:"permission,omitempty"`
	SecretFields []string    `json:"secret_fields,omitempty"`
	Pagination   *Pagination `json:"pagination,omitempty"`
	Note         string      `json:"note,omitempty"`
	// Listing names the operation that lists a download's parts with their sizes
	// (same path parameters except the last, which names the part). An empty
	// download of a part it lists as not empty is a failure.
	Listing string `json:"listing,omitempty"`
}

Policy is the merged entry from spec/operation-policy.yaml.

func (Policy) SecretOutput

func (p Policy) SecretOutput() bool

SecretOutput reports whether the operation returns a one-time secret that needs an explicit destination.

type Response

type Response struct {
	Kind         string   `json:"kind"`
	ContentTypes []string `json:"content_types,omitempty"`
}

Response describes the success response.

type Source

type Source struct {
	Repository     string `json:"repository"`
	Tag            string `json:"tag"`
	Commit         string `json:"commit"`
	SpecPath       string `json:"spec_path"`
	SpecSHA256     string `json:"spec_sha256"`
	Exporter       string `json:"exporter"`
	RestishModule  string `json:"restish_module"`
	RestishVersion string `json:"restish_version"`
}

Source records where the pinned spec came from (spec/source.lock.json).

Jump to

Keyboard shortcuts

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