cli

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Overview

Package cli holds siding's commands: flags, arguments and output. What a command prints with --json is defined in json.go.

Index

Constants

View Source
const (
	// CodeInvalidArguments: unknown command, flag or argument.
	CodeInvalidArguments = fail.InvalidArguments
	// CodeInternal: an unexpected error without a code of its own.
	CodeInternal = fail.Internal
)

Error codes Execute uses itself; the rest are in package fail.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, root *cobra.Command, args []string, stdout, stderr io.Writer) int

Execute runs root with args and returns the exit code. A failure is printed as an Error document on stdout when --json was given, and as one line (and a hint) on stderr otherwise.

func New

func New(opts Options) *cobra.Command

New returns the root command.

Types

type Browser

type Browser interface {
	Open(url string) error
}

Browser opens a URL.

type BuildInfo

type BuildInfo struct {
	Version   string
	Commit    string
	GoVersion string
	Platform  string
}

BuildInfo describes the running binary.

func CurrentBuild

func CurrentBuild(version string) BuildInfo

CurrentBuild returns the BuildInfo of this binary; the commit comes from the VCS stamp Go writes into it.

type Clock

type Clock interface {
	Now() time.Time
	Sleep(ctx context.Context, d time.Duration) error
}

Clock is the time, for waiting.

type Compose

type Compose interface {
	Config(ctx context.Context, inv compose.Invocation) ([]byte, error)
	UnresolvedConfig(ctx context.Context, inv compose.Invocation) ([]byte, error)
	Run(ctx context.Context, inv compose.Invocation, args []string, stdout, stderr io.Writer) error
}

Compose runs docker compose.

type Docker

type Docker interface {
	Ping(ctx context.Context) error
	Containers(ctx context.Context, labels map[string]string) ([]docker.Container, error)
	Container(ctx context.Context, name string) (*docker.Container, error)
	Networks(ctx context.Context, labels map[string]string) ([]docker.Network, error)
	Volumes(ctx context.Context, labels map[string]string) ([]docker.Volume, error)
	EnsureNetwork(ctx context.Context, name string, labels map[string]string) (bool, error)
	MemTotal(ctx context.Context) (int64, error)
	NetworkGateway(ctx context.Context, name string) (string, error)
	NetworkUsers(ctx context.Context, name string) (exists bool, users []string, err error)
	RemoveNetwork(ctx context.Context, name string) error
	NCPU(ctx context.Context) (int, error)
	CreateVolume(ctx context.Context, name string, labels map[string]string) error
	RemoveVolume(ctx context.Context, name string) error
	VolumeSizes(ctx context.Context) (map[string]int64, error)
	RunHelper(ctx context.Context, h docker.Helper) (exit int, output []string, err error)
	Logs(ctx context.Context, id string, tail int) ([]string, error)
	Stdout(ctx context.Context, id string) ([]string, error)
	Memory(ctx context.Context, id string) (uint64, error)
}

Docker reads state from the Docker Engine API.

type Error

type Error = fail.Error

Error is a failure with a stable code, which agents may branch on.

type Git

type Git interface {
	Worktree(ctx context.Context, dir string) (git.Worktree, error)
	Top(ctx context.Context, dir string) (string, error)
	Tracked(ctx context.Context, top, path string) (bool, error)
	Dirty(ctx context.Context, top string) (bool, error)
	MergeState(ctx context.Context, r git.Repo, branch string) (git.MergeState, error)
}

Git answers questions about worktrees.

type Options

type Options struct {
	Build BuildInfo
	// Dir is the current directory.
	Dir string
	// Home is the user's home directory, for the cache under ~/.siding.
	Home string
	// Getenv reads an environment variable.
	Getenv func(string) string
	// OSMachineID returns the operating system's machine id, or "".
	OSMachineID func() string
	// PID is siding's process id, and Alive reports whether a process still runs (the queue).
	PID   int
	Alive func(pid int) bool
	// IsLocalAddress reports whether an IP address belongs to this machine.
	IsLocalAddress func(ip string) bool
	// Stdin is where questions are answered; IsTerminal reports whether a human is there.
	Stdin      io.Reader
	IsTerminal func() bool

	Git     Git
	Compose Compose
	Docker  Docker
	Probe   Prober
	Browser Browser
	Clock   Clock
	// Proxy names siding-proxy and its network.
	Proxy proxy.Config
}

Options holds everything a command needs from the machine it runs on. Tests pass their own, so no package-level variable is a test seam and tests can run in parallel.

type Prober

type Prober interface {
	Get(ctx context.Context, addr, host, path string) (probe.Response, error)
}

Prober sends one request through the proxy.

type SystemBrowser

type SystemBrowser struct {
	Getenv func(string) string
}

SystemBrowser opens URLs with the platform's opener: open on macOS, $BROWSER (set by VS Code in a devcontainer) or xdg-open on Linux.

func (SystemBrowser) Open

func (b SystemBrowser) Open(url string) error

Open opens url.

type SystemClock

type SystemClock struct{}

SystemClock is the real time.

func (SystemClock) Now

func (SystemClock) Now() time.Time

Now returns the current time.

func (SystemClock) Sleep

func (SystemClock) Sleep(ctx context.Context, d time.Duration) error

Sleep waits for d or until ctx is done.

Jump to

Keyboard shortcuts

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