servicecontract

package
v1.0.0-rc.16 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 1 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 servicecontract defines the human and machine readable description of an application service exposed through product surfaces.

Index

Constants

View Source
const (
	FlagScopeCommand    = "command"
	FlagScopePersistent = "persistent"
)

Flag scope values. A command flag belongs to one operation; a persistent flag is registered once on the root command and read by every operation below it.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contract

type Contract struct {
	ID          string      `json:"id"`
	Summary     string      `json:"summary"`
	Description string      `json:"description"`
	Operations  []Operation `json:"operations"`
}

Contract describes one service and the operations a surface may expose.

func (Contract) Operation

func (c Contract) Operation(id string) (Operation, bool)

Operation returns the operation with id.

func (Contract) Validate

func (c Contract) Validate() error

Validate rejects contracts whose identifiers or readable descriptions are incomplete.

type Example

type Example struct {
	Command     string `json:"command"`
	Explanation string `json:"explanation,omitempty"`
}

Example is one worked invocation of an operation.

type FlagSpec

type FlagSpec struct {
	Name      string `json:"name"`
	Shorthand string `json:"shorthand,omitempty"`
	Scope     string `json:"scope,omitempty"`
	Hidden    bool   `json:"hidden,omitempty"`
}

FlagSpec is the command-line flag an input is reached through.

type Input

type Input struct {
	ID       string `json:"id"`
	Summary  string `json:"summary"`
	Type     string `json:"type"`
	Required bool   `json:"required,omitempty"`
	// Values enumerates the accepted values of a closed input, so a surface can
	// offer the choice instead of restating it.
	Values []string `json:"values,omitempty"`
	// Flag is the command-line spelling of this input. An empty Name means the
	// input is reached positionally or not at all.
	Flag FlagSpec `json:"flag,omitempty"`
	// Positional is the 1-based ordinal this input occupies, or zero when it has
	// no positional form.
	Positional int `json:"positional,omitempty"`
	// Variadic marks an input that consumes the remaining positionals and is
	// therefore always the last one.
	Variadic bool `json:"variadic,omitempty"`
	// Default is what the surface applies when the operator states nothing. An
	// empty Default means the input has no default.
	Default string `json:"default,omitempty"`
	// Placeholder is the metavar the synopsis renders for this input.
	Placeholder string `json:"placeholder,omitempty"`
	// Repeatable marks a flag or positional that may be given more than once.
	Repeatable bool `json:"repeatable,omitempty"`
	// Presentation marks an input the surface renders and that changes no
	// engine input, so a coverage check does not demand a request field for it.
	Presentation bool `json:"presentation,omitempty"`
	// Deprecated names the replacement or the reason a spelling is kept, so a
	// surface can warn instead of silently dropping it.
	Deprecated string `json:"deprecated,omitempty"`
}

Input describes one named operation input.

type Operation

type Operation struct {
	ID          string  `json:"id"`
	Summary     string  `json:"summary"`
	Description string  `json:"description,omitempty"`
	Inputs      []Input `json:"inputs,omitempty"`
	// Spec is the operator-facing body of the operation: what the capability
	// is, what it refuses and what it costs. It is the whole of what a surface
	// renders as long help.
	Spec string `json:"spec,omitempty"`
	// Usage is the synopsis a command surface renders after the command path,
	// carrying the positional placeholders the operation accepts.
	Usage    string    `json:"usage,omitempty"`
	Examples []Example `json:"examples,omitempty"`
	Output   Output    `json:"output,omitempty"`
	Outcomes []Outcome `json:"outcomes,omitempty"`
	// Gate names the visibility gate the operation sits behind, so a surface
	// hides it rather than offering a command that cannot run.
	Gate     string    `json:"gate,omitempty"`
	Refusals []Refusal `json:"refusals,omitempty"`
}

Operation describes one callable operation.

type Outcome

type Outcome struct {
	Code    int    `json:"code"`
	When    string `json:"when"`
	Meaning string `json:"meaning,omitempty"`
}

Outcome is one terminal status an operation reports.

type Output

type Output struct {
	Stdout string `json:"stdout,omitempty"`
	Stderr string `json:"stderr,omitempty"`
	Format string `json:"format,omitempty"`
}

Output describes what an operation writes where.

type Refusal

type Refusal struct {
	When    string `json:"when"`
	Message string `json:"message"`
}

Refusal is one condition under which an operation declines, with what the surface tells the operator when it does.

Jump to

Keyboard shortcuts

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