extension

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package extension runs a Go extension from one value, as SDK in contract.md defines: started as ncly-<domain>, or compiled into ncly and started by it under that name. Either way it parses the call with its manifest, runs the handler of the command, and prints the answer by the kind of the command's result.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(e Extension) error

Check reports what Main would refuse, and a catalog that breaks the catalog rules of SDK in contract.md. Every Go extension has a test that calls it.

func Main

func Main(e Extension)

Main runs the extension as this process with the arguments of the process, then exits with its exit code.

Types

type Call

type Call struct {
	// Path is the command path, such as "hello run".
	Path string
	// Args holds the positional arguments.
	Args []string
	// Flags holds each flag that the caller set, by long name. A switch
	// holds "true" or "false".
	Flags   map[string]string
	JSON    bool
	Mode    contract.Mode
	Printer *i18n.Printer
	Stdin   io.Reader
	// Stdout takes human text only: the SDK prints the answer. Under --json,
	// it discards what a command other than a text command writes.
	Stdout io.Writer
	Stderr io.Writer
}

Call is one validated call of a command.

type Extension

type Extension struct {
	// Manifest holds manifest.toml.
	Manifest []byte
	// Locales holds locales/<lang>.toml.
	Locales fs.FS
	// Handlers holds one handler per command that runs, keyed by path,
	// such as "hello run".
	Handlers map[string]Handler
}

Extension is a Go extension: its manifest, its catalogs, and one handler per command that runs.

type Handler

type Handler func(ctx context.Context, call Call) contract.Outcome

Handler runs one validated call. ctx ends on the first Ctrl-C or SIGTERM, and the handler then returns what it has.

Jump to

Keyboard shortcuts

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