cli

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package cli owns Starport command contracts and process-independent execution.

Index

Constants

View Source
const (
	// ExitCodeRuntime reports an application or dependency failure.
	ExitCodeRuntime = 1
	// ExitCodeUsage reports invalid command syntax or arguments.
	ExitCodeUsage = 2
)

Variables

View Source
var (
	// ErrStdinRequired reports a missing command input stream.
	ErrStdinRequired = errors.New("command input is required")
	// ErrStdoutRequired reports a missing command output stream.
	ErrStdoutRequired = errors.New("command output is required")
	// ErrStderrRequired reports a missing command error stream.
	ErrStderrRequired = errors.New("command error output is required")
	// ErrServerRunnerRequired reports a missing server runtime boundary.
	ErrServerRunnerRequired = errors.New("server runner is required")
	// ErrInitializerRequired reports a missing setup runtime boundary.
	ErrInitializerRequired = errors.New("initializer is required")
	// ErrConfigLoaderRequired reports a missing configuration reader.
	ErrConfigLoaderRequired = errors.New("configuration loader is required")
	// ErrPathResolverRequired reports a missing platform-path reader.
	ErrPathResolverRequired = errors.New("configuration path resolver is required")
	// ErrDiagnoserRequired reports a missing diagnostic runtime boundary.
	ErrDiagnoserRequired = errors.New("diagnoser is required")
)
View Source
var (
	// ErrDevelopmentStarterRequired reports a missing development boundary.
	ErrDevelopmentStarterRequired = errors.New("development starter is required")
	// ErrDevelopmentSessionInvalid reports an incomplete development session.
	ErrDevelopmentSessionInvalid = errors.New("development session is invalid")
)
View Source
var ErrDiagnosisFailed = errors.New("diagnosis failed")

ErrDiagnosisFailed reports one or more failed diagnostic checks.

View Source
var ErrNoClipboard = errors.New(
	"no clipboard command was found on this machine; pipe the link instead, " +
		"for example `starport auth url | pbcopy`",
)

ErrNoClipboard reports a machine with no clipboard command this build knows how to drive. It names the alternative, because piping the URL is what an operator would have done anyway and the command still printed it.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps a command error to a process exit code.

func New

func New(deps Dependencies) (*urfavecli.Command, error)

New creates the Starport root command.

func Run

func Run(ctx context.Context, args []string, deps Dependencies) error

Run builds and executes the command for the supplied argument slice.

func WriteVersion

func WriteVersion(w io.Writer, info BuildInfo, asJSON bool) error

WriteVersion writes build information in text or JSON format.

Types

type BrowserOpener added in v1.1.0

type BrowserOpener func(url string) error

BrowserOpener opens a URL in the operator's browser.

type BuildInfo

type BuildInfo struct {
	Version   string `json:"version"`
	BuildTime string `json:"build_time"`
	GitCommit string `json:"git_commit"`
	GitBranch string `json:"git_branch"`
	GoVersion string `json:"go_version"`
	OS        string `json:"os"`
	Arch      string `json:"arch"`
}

BuildInfo contains immutable binary build information.

type ClipboardWriter added in v1.1.0

type ClipboardWriter func(ctx context.Context, text string) error

ClipboardWriter puts text on the operator's clipboard. It takes a context because the real implementation runs another program, and an operator who interrupts the command should not be left waiting on a wedged one.

type ConfigLoader

type ConfigLoader func(context.Context) (*config.Config, error)

ConfigLoader reads and validates effective configuration.

type Dependencies

type Dependencies struct {
	Stdin            io.Reader
	Stdout           io.Writer
	Stderr           io.Writer
	Build            BuildInfo
	RunServer        ServerRunner
	StartDevelopment DevelopmentStarter
	Initialize       Initializer
	LoadConfig       ConfigLoader
	ResolvePaths     PathResolver
	Diagnose         Diagnoser
	// Desktop reaches the operator's machine. It is not validated: a machine
	// with no browser and no clipboard still runs every command, because each
	// one prints the link it would otherwise have handed over.
	Desktop Desktop
	// ExtraCommands appends process-owned commands to the root command tree.
	// The process boundary owns commands whose behavior binds to its build,
	// such as the embedded agent skill and the catalog verbs.
	ExtraCommands []*urfavecli.Command
}

Dependencies contains all runtime boundaries used by commands.

type Desktop added in v1.1.0

type Desktop struct {
	OpenBrowser     BrowserOpener
	CopyToClipboard ClipboardWriter
	IsTerminal      TerminalCheck
}

Desktop reaches the machine the operator is sitting at: their browser, their clipboard, and whether anyone is watching the output at all.

Every field is optional, and a nil field selects the real implementation. The three travel together because they answer one question — what this run can do beyond writing text — and a test that wants to observe one usually wants to fix the others too.

type DevelopmentSession added in v1.0.3

type DevelopmentSession struct {
	URL    string
	APIKey string
	// ConsoleURL signs one browser in to this session. It is a separate value
	// from URL and from APIKey because it is a separate credential: it opens a
	// console session and grants no gateway API key, and it is spent the first
	// time it is followed.
	ConsoleURL string
	// AuthDisabled reports that the session serves requests without a gateway
	// API key. It is what makes an empty APIKey legitimate rather than a bug.
	AuthDisabled bool
	Run          func(context.Context) error
	Close        func(context.Context) error
}

DevelopmentSession contains one ephemeral gateway and its one-time key.

type DevelopmentStarter added in v1.0.3

type DevelopmentStarter func(context.Context, GatewayOptions) (DevelopmentSession, error)

DevelopmentStarter creates one isolated local gateway session.

type Diagnoser

Diagnoser runs read-only startup checks.

type GatewayOptions added in v1.1.0

type GatewayOptions struct {
	// DisableAuth serves requests without a gateway API key.
	DisableAuth bool
	// AllowRemoteNoAuth acknowledges an unauthenticated gateway on an address
	// the network can reach. It lifts a startup refusal and nothing else.
	AllowRemoteNoAuth bool
}

GatewayOptions carries the gateway decisions a command line can make. They are decisions, not configuration: everything else the gateway reads comes from the environment and the configuration file, and these exist because an operator has to be able to make them for one run without editing either.

type InitOptions

type InitOptions struct {
	APIKeyName        string
	ConfiguredStorage bool
}

InitOptions contains explicit local initialization choices.

type InitResult

type InitResult struct {
	APIKeyName string                      `json:"api_key_name"`
	ConfigFile string                      `json:"config_file,omitempty"`
	DataDir    string                      `json:"data_dir,omitempty"`
	APIKey     string                      `json:"api_key"`
	Rollback   func(context.Context) error `json:"-"`
}

InitResult contains initialized paths and the one-time gateway credential.

type Initializer

type Initializer func(context.Context, InitOptions) (InitResult, error)

Initializer creates local state and returns the new gateway credential once.

type PathResolver

type PathResolver func() (config.Paths, error)

PathResolver resolves platform configuration and data paths.

type ServerRunner

type ServerRunner func(context.Context, GatewayOptions) error

ServerRunner starts the gateway and blocks until it stops.

type TerminalCheck added in v1.1.0

type TerminalCheck func(writer io.Writer) bool

TerminalCheck reports whether a command's output reaches a person.

Jump to

Keyboard shortcuts

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