cli

package
v0.0.0-...-99cc010 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package cli implements Locorum's command-line surface. The same binary that runs the GUI parses os.Args before app.Main() and dispatches a CLI subcommand here when one is recognised. Every mutating command in this package shells JSON-RPC over the IPC socket to the daemon — this package never talks to Docker / SQLite directly.

Output rules:

  • Tables go to stdout, errors to stderr.
  • Exit codes are documented per command (0 = success, 1 = error, 2 = invalid usage, 3 = no daemon).
  • --json prints JSON-encoded results, suitable for scripting.
  • NO_COLOR and a non-TTY stdout both suppress ANSI sequences.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCLIInvocation

func IsCLIInvocation(args []string) bool

IsCLIInvocation is the public hook main.go uses. Same as isCLIVerb but exported so the package boundary is explicit.

func IsDaemonVerb

func IsDaemonVerb(args []string) bool

IsDaemonVerb reports whether os.Args asks for an explicit daemon boot. Distinct from auto-spawn: the user can run `locorum daemon` to get a headless process for CI.

Types

type Command

type Command interface {
	Name() string
	Synopsis() string
	Run(ctx context.Context, env *Env) ExitCode
}

Command is the runtime contract every subcommand satisfies.

type Env

type Env struct {
	Stdout  io.Writer
	Stderr  io.Writer
	Args    []string // arguments AFTER the subcommand keyword
	HomeDir string
	ExePath string // absolute path to the locorum binary, for auto-spawn
	Version string
}

Env carries every dependency a CLI command needs. Constructed once per invocation by main.go; injected into every subcommand so tests can capture stdout/stderr without process-global state.

func NewEnv

func NewEnv(args []string, version string) *Env

NewEnv builds a default Env from the running process. CLI entry-point calls NewEnv to keep the wire-up in one place.

type ExitCode

type ExitCode int

ExitCode classifies the outcome of a CLI invocation. Numeric values are part of the public contract — scripts depend on them.

const (
	ExitOK         ExitCode = 0
	ExitError      ExitCode = 1
	ExitUsage      ExitCode = 2
	ExitNoDaemon   ExitCode = 3
	ExitNotFound   ExitCode = 4
	ExitForbidden  ExitCode = 5
	ExitConflict   ExitCode = 6
	ExitNotStarted ExitCode = 7
)

func Dispatch

func Dispatch(args []string, env *Env) (ExitCode, bool)

Dispatch is the entry point called by main.go when os.Args[1] looks like a CLI subcommand. Returns true if the args were consumed (the caller exits with the returned code); false means "no subcommand recognised, continue to GUI."

Jump to

Keyboard shortcuts

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