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

cli

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package cli is the wctr command: subcommands in the familiar container CLI grammar (pull, run, ps, logs, rm, rmi, inspect, images) speaking the engine's API, which is compatible with the Docker Engine API.

It is a package so that the command runs anywhere a client can reach a daemon: cmd/wctr over a unix socket, the browser playground in-process through an in-memory transport. It imports no runtime and nothing native, so it also builds for GOOS=wasip1 and GOOS=js.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exit

func Exit(code int) error

Exit is a status RunE wants the process to end with (`wctr run` returns the container's).

func Report

func Report(w io.Writer, err error) int

Report prints err the way the command does and returns the exit status.

func RootCmd

func RootCmd(o Options) *cobra.Command

RootCmd builds the command tree.

Types

type Candidate added in v0.3.0

type Candidate struct {
	Value       string `json:"value"`
	Description string `json:"description,omitempty"`
}

Candidate is one completion choice.

type Completion added in v0.3.0

type Completion struct {
	Candidates []Candidate
	Directive  cobra.ShellCompDirective
}

Completion is what cobra's __complete answered.

func Complete added in v0.3.0

func Complete(ctx context.Context, o Options, words []string) (Completion, error)

Complete runs the hidden __complete command in-process for words (the arguments after "wctr"; the last one is the word being completed, "" for a new word) and parses its output: one "value[\tdescription]" per line, then ":<directive>". This is what a shell's completion script does by running the binary; the playground's line editor does it here.

func (Completion) Failed added in v0.3.0

func (c Completion) Failed() bool

Failed reports the Error directive (ignore the candidates).

func (Completion) NoSpace added in v0.3.0

func (c Completion) NoSpace() bool

NoSpace reports the NoSpace directive (no space after a unique match).

type Engine added in v0.12.0

type Engine struct {
	// Client connects through the CLI's own -H handling.
	Client func() (*api.Client, error)
}

Engine is how an extra command reaches the engine -H names.

func (Engine) HTTP added in v0.12.0

func (e Engine) HTTP() (*nethttp.Client, string, error)

HTTP returns the engine's HTTP client and base URL (requests go to base + "/v1.47/…" or unversioned paths).

type Options

type Options struct {
	// Version is what --version and `wctr version` print (default "dev").
	Version string
	// DefaultHost is the -H default (default api.DefaultHost()).
	DefaultHost string
	// Client connects to a host; nil means api.NewClient.
	Client func(host string) (*api.Client, error)
	// LookupEnv resolves `-e KEY` (default os.LookupEnv).
	LookupEnv func(string) (string, bool)
	// PullCandidates, when set, adds pullable images to the completion of
	// pull and run (the playground's mirror catalogue).
	PullCandidates func(context.Context) []cobra.Completion
	// RunArgs, when set, completes the arguments after the image of run
	// (the playground knows its lab image's subcommands).
	RunArgs func(image string, args []string) []cobra.Completion
	// NoCompletionCommand removes cobra's `completion` command (scripts
	// for a shell the host does not have, as in the browser).
	NoCompletionCommand bool
	// Extra adds commands from other modules (`wctr build`, `wctr
	// compose`) to the tree. Each is made once per RootCmd and receives a
	// way to reach the engine selected by -H: Engine returns its HTTP
	// client and base URL (or an *api.Client through Client).
	Extra []func(Engine) *cobra.Command
}

Options configure a command tree.

Directories

Path Synopsis
Package lineedit is wctr's interactive line editor, as a pure model: key events in, the line, the cursor, candidate listings and submitted lines out.
Package lineedit is wctr's interactive line editor, as a pure model: key events in, the line, the cursor, candidate listings and submitted lines out.

Jump to

Keyboard shortcuts

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