cli

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 57 Imported by: 0

Documentation

Overview

Package cli wires the declarative spec into a cobra command tree, parses and validates input, and enforces the output contract: one JSON document on stdout, diagnostics and one structured error on stderr, and the documented exit codes. cobra handles parsing and dispatch; help, the error envelope, and exit codes are owned here so the agent contract holds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(args []string, d Deps) int

Execute builds and runs the CLI for args, returning the process exit code.

func RenderCommandHelp

func RenderCommandHelp(c surfaceCmd, experimental bool) string

RenderCommandHelp renders per-command help from the unified surface. The program name in the usage line and examples comes from progname.Name().

experimental gates the command's opt-in, not-yet-stable surface: when false (plain `--help`), experimental flags/notes/examples are omitted and a single pointer note tells the reader how to reveal them; when true (help requested with --enable-experimental), they are shown, the experimental notes/examples appended after the stable ones, and each experimental flag tagged.

func RenderGroupHelp

func RenderGroupHelp(path ...string) string

RenderGroupHelp renders focused help for a command group (e.g. `mcp`, `order`, `key`, or a nested group like `sandbox runtime`): the group's subcommands with their summaries, so `<prog> <group> --help` shows what is available instead of dumping the full root help. Falls back to root help if path is not a known group. The program name comes from progname.Name().

func RenderRootHelp

func RenderRootHelp() string

RenderRootHelp renders the top-level help from the spec. The program name comes from progname.Name().

Types

type Deps

type Deps struct {
	Getenv func(string) string
	Stdout io.Writer
	Stderr io.Writer
	Doer   korbit.Doer
	Now    func() int64
	// Sleep delays between auto-retries; defaults to time.Sleep. Tests inject a
	// no-op so the retry layer runs instantly.
	Sleep func(time.Duration)
	// IPProbe fetches the public IP over a given network family for the `ip`
	// command and `setup`. Defaults to a netbind family-pinned probe; tests stub it.
	IPProbe korbit.IPProber
	// FamilyDoer returns a Doer pinned to a TCP family ("tcp4"/"tcp6"); doctor
	// uses it to replay a signed request over each family to diagnose an
	// IP-allowlist rejection. Defaults to a netbind family-pinned doer; tests stub it.
	FamilyDoer func(network string, timeoutMs int) korbit.Doer
	// WSDial opens the monitor/tui commands' WebSocket connections. Defaults
	// to stream.DefaultDialer; tests inject a fake.
	WSDial stream.Dialer
	// TUIRun runs the interactive terminal for the `tui` command. nil means
	// the real implementation (tui.Run), which requires stdout to be a TTY;
	// tests inject a stub.
	TUIRun func(tui.Config) error
	// SetupUIRun runs the interactive prompt for `setup` on a TTY. nil means the
	// real implementation (setupui.Run), which requires stdin/stderr to be a TTY;
	// tests inject a stub (and injecting one forces the interactive path on,
	// bypassing the TTY gate, so the wiring is exercisable in-process).
	SetupUIRun func(setupui.Config) error
	// SelfUninstallConfirm is the yes/no prompt `self uninstall` asks its removal
	// questions through. nil means the real stdin-backed confirmer (which needs a
	// terminal); tests inject a scripted one (which also forces the interactive
	// path on, bypassing the TTY gate, so the destructive flow is exercisable
	// in-process).
	SelfUninstallConfirm clienv.Confirm
	// SkillFS is the embedded Agent Skill content, rooted at the skill directory
	// (SKILL.md at the top), used by `agent skill install`/`doctor`. main injects
	// the //go:embed FS; tests inject a fstest.MapFS. nil only on a build that
	// didn't wire it — the agent-skill commands then fail with a clear error.
	SkillFS fs.FS
}

Deps are the injectable dependencies, so the whole CLI runs in-process under test with buffers, a stub HTTP client, a temp home, and a fixed clock.

Directories

Path Synopsis
Package agentskillcmd implements the `agent skill …` builtins: install the bundled Agent Skill onto disk for each supported agent, and a doctor that reports install/drift/PATH health.
Package agentskillcmd implements the `agent skill …` builtins: install the bundled Agent Skill onto disk for each supported agent, and a doctor that reports install/drift/PATH health.
Package clienv is the seam between the cli command tree and the command subpackages it dispatches into.
Package clienv is the seam between the cli command tree and the command subpackages it dispatches into.
Package doctorcmd implements the `doctor` command: a read-only assessment of whether the current key configuration can reach and trade on Korbit, with a fix named for every problem.
Package doctorcmd implements the `doctor` command: a read-only assessment of whether the current key configuration can reach and trade on Korbit, with a fix named for every problem.
Package keymgmtcmd implements the key & keystore management commands — `setup`, the `key` group (add/bind/use/rename/remove/list/show/set-base-url/ set-default-account-seq), and the `keystore` group (status/migrate/default).
Package keymgmtcmd implements the key & keystore management commands — `setup`, the `key` group (add/bind/use/rename/remove/list/show/set-base-url/ set-default-account-seq), and the `keystore` group (status/migrate/default).
Package monitorcmd implements the `monitor` command — the CLI's one streaming command and its experimental JavaScript bot runtime.
Package monitorcmd implements the `monitor` command — the CLI's one streaming command and its experimental JavaScript bot runtime.
Package probe holds the endpoint-soundness and reachability primitives the cli's onboarding and diagnostic commands share (ip, doctor, setup, key set-base-url, mcp): base-URL validation, the public-IP probe and its allowlist report, the REST/WebSocket reachability smoke test, and the IP-allowlist error classifier.
Package probe holds the endpoint-soundness and reachability primitives the cli's onboarding and diagnostic commands share (ip, doctor, setup, key set-base-url, mcp): base-URL validation, the public-IP probe and its allowlist report, the REST/WebSocket reachability smoke test, and the IP-allowlist error classifier.
Package sandboxcmd implements the `sandbox …` builtin group: the lifecycle manager for the local Korbit API Sandbox.
Package sandboxcmd implements the `sandbox …` builtin group: the lifecycle manager for the local Korbit API Sandbox.
Package selfcmd implements the `self install|update|uninstall|doctor` builtins: the CLI-facing layer over internal/selfupdate.
Package selfcmd implements the `self install|update|uninstall|doctor` builtins: the CLI-facing layer over internal/selfupdate.
Package setupui is the interactive terminal front-end for the `setup` command.
Package setupui is the interactive terminal front-end for the `setup` command.
Package textout holds the command-agnostic human-output toolkit: the table, key/value and number-formatting primitives the cli's human-readable mode is built from, plus the TextFormatter seam a command's result type implements to render itself.
Package textout holds the command-agnostic human-output toolkit: the table, key/value and number-formatting primitives the cli's human-readable mode is built from, plus the TextFormatter seam a command's result type implements to render itself.
Package tuicmd implements the `tui` command — the interactive, full-screen trading terminal (the human sibling of monitor).
Package tuicmd implements the `tui` command — the interactive, full-screen trading terminal (the human sibling of monitor).

Jump to

Keyboard shortcuts

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