cli

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: LGPL-2.1 Imports: 16 Imported by: 0

README

mod/cli

mod/cli parses command-line arguments and selects the top-level process mode. It is the boundary between user input and runtime assembly: server start, config validation, preset generation, key generation, storage inspection, and maintenance all begin here.

Place in the Runtime

flowchart TB
  argv["argv"] --> cli["mod/cli"]
  cli --> run["server runtime"]
  cli --> validate["validate config"]
  cli --> presets["write presets"]
  cli --> keygen["make Yggdrasil key"]
  cli --> maintenance["inspect, prune, vacuum, rebuild-cache"]

Responsibilities

  • Parse flags and positional config paths.
  • Return a typed command for the root runtime instead of starting subsystems directly.
  • Keep CLI output and errors in English.
  • Support --json output envelopes for automation.
  • Route maintenance commands to storage-only paths that require exclusive access.

Contracts

  • CLI parsing must not open storage, start mesh, or start HTTP listeners.
  • Maintenance commands must validate that they have enough input before touching storage.
  • --make-preset, --validate-config, and --make-ygg-key are one-shot commands and should not assemble the server.
  • User-facing command text is part of the operator interface and should remain stable.

Important Files

  • obj.go: command object and parser entry.
  • parse.go: flag and argument parsing.
  • command.go: typed command definitions.
  • json.go: JSON envelope output.
  • usage.go: help text.

Operational Notes

Prefer explicit commands in automation. yggvault <config> is convenient for humans; yggvault --config <config> is clearer in service units and scripts.

Documentation

Index

Constants

View Source
const (

	// Maintenance command names are public and shared by cli flags/validation/help and root main JSON rendering.
	CommandInspect      = "inspect"
	CommandPrune        = "prune"
	CommandVacuum       = "vacuum"
	CommandRebuildCache = "rebuild-cache"
)

Variables

This section is empty.

Functions

func RenderError

func RenderError(err error) bool

RenderError renders a CLI error: JSON envelope with --json, colored stderr otherwise.

Types

type KeygenObj

type KeygenObj struct {
	MakeYggKey bool
	Force      bool // overwrite existing key file
	JsonOutput bool // machine-readable output
}

KeygenObj is the config-less ygg key generation command. cli only recognizes and validates it; main generates, writes, and renders the result.

func (KeygenObj) Requested

func (obj KeygenObj) Requested() bool

Requested reports whether key generation was requested.

type MaintenanceObj

type MaintenanceObj struct {
	Inspect      bool
	Prune        bool
	Vacuum       bool
	RebuildCache bool
	Force        bool // apply --prune; without it prune is dry-run
	JsonOutput   bool // machine-readable output
}

MaintenanceObj holds the requested CLI maintenance command. cli only recognizes and validates it; main opens storage, executes work, and renders output.

func (MaintenanceObj) Requested

func (obj MaintenanceObj) Requested() bool

Requested reports whether any maintenance command was requested.

type Obj

type Obj struct {
	Config      *stcfg.ConfigObj
	Logger      *logger.Obj
	Maintenance MaintenanceObj
	Keygen      KeygenObj
}

Obj is the CLI bootstrap result for runtime mode: validated config, ready logger, and requested maintenance flags. New returns it; root main performs module orchestration.

func New

func New() (*Obj, error)

New is the full CLI bootstrap point: it parses argv, handles help/info/preset/validate, and returns validated config plus initialized logger in runtime mode.

Jump to

Keyboard shortcuts

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