Every argument and flag error is a devvm message naming what the command
expected, followed by usage_help naming that command's own --help, and
exits with 2. Arguments and flag values are checked in Args, before the
root's PersistentPreRun and any VM lookup.
- internal/cli/args.go: noArgs, exactArgs, maxArgs, minArgs (argsN, with
ValidArgs), argsOf (the arguments in Use), checkCommands (wraps every
command's Args with checkFlags and marks RunE's errors as ranError),
checkFlagValue (--cpus, --memory, --disk, --ports, --lifetime,
--older-than), exclusive (flag groups checked first, then Cobra's own
required flags and groups), flagError (SetFlagErrorFunc: pflag's
NotExist, ValueRequired, InvalidValue, InvalidSyntax errors).
- Execute: 0, 1 for a failure (RunE's error: a message, or
output_failed), 2 for a usage error; usage_error is only the fallback.
- Checked early: ports LIST and add/rm LIST (vm.ParsePortList), network
allow/deny RULEs, network on/off(/ask with -g), layer new NAME
(build.CheckLayerName), retention KEY=VALUE (state.CheckRetention),
setup --features '', secret NAME, completion SHELL, git-protect and
ssh-agent values.
- ui.UI.Error prints an error without ending the run (UI's method limit
44).
- Messages: usage_help, arg_missing, args_too_many, args_none,
arg_not_choice, no_subcommand, flag_unknown, flag_needs_value,
flag_bad_value, flag_bad_switch, flags_exclusive, output_failed;
usage_error reworded; doc links to troubleshooting.
- Tests: TestUsageErrorsEveryCommand, TestRanErrorIsAFailure, TestArgsOf,
TestFlagErrors; txtars check message names; e2e checks a bad port list
exits 2.
- Docs: troubleshooting (a command refused before it runs, exit codes),
contributing (command arguments), AGENTS.md.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
internal/ui has no package state: ui.UI holds the streams, terminal
flags, run log, status line, cleanup stack and interrupt flag, and its
functions are methods. ui.Main makes the run's UI on devvm's own
streams, owns signals, recovers Die and runs the cleanups; ui.New makes
one on other streams. cmd/devvm passes it to cli.Execute, and every cli
command gets it through its constructor.
Only cmd/devvm and internal/cli import internal/ui (a depguard rule).
Each other package defines the small UI interface it needs, which its
constructor takes, filling fields tests set:
- gitprotect.New, secrets.NewStore, from.NewLookup: a warn func
- ubuntu.New: LoggedCmd, Note
- netpolicy.NewProxy: Note, Warn, Ask, Confirm, StdinIsTerminal; its
log lines drop control characters themselves (oneLine)
- sshagent.New: Info, Note, Warn, LogWriter
- tools.New: Info, Warn, LogNote, Status, LoggedCmd, AddCleanup
- lima.New, smolvm.New: Info, Warn, LoggedCmd (their Runner's Run),
WithSteps, AddCleanup, Interrupted; lima LogNote and ubuntu's too
- backends.Registry: lima's and smolvm's
- vm.NewEnv: all of the above, Say, Stdout, Stderr; Env has Stdout,
LogNote, LogWriter, LoggedCmd, AddCleanup, Interrupted fields
- build.Builder: Terminal and LogNote fields
- sshconfig.New: its caller sets what it prints and asks
ui's tests build their own UI over buffers and run in parallel; other
packages' tests use small fakes; cli's unit tests a UI over buffers.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
internal/ui is now the only package that prints: the message helpers,
prompts, tty detection, the status line, the run log (Logged, step
counts, proxy keys redacted) and ui.Main, which recovers Die, runs the
cleanup stack and handles INT/TERM/HUP (exit 130). main runs devvm
through it, and Cobra's errors print as one-line devvm errors.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
locales/en.toml holds every message; go generate ./internal/msg writes
one typed function per message. internal/msg renders them through a
go-i18n bundle in the user's language (LC_ALL, LC_MESSAGES, LANG), with
names mode (DEVVM_MESSAGES=names) and doc links. devvm _msg prints a
message's text. Tests check the generated file is current, every
message renders and is called, and every doc link exists; lint runs
the doc link check.
Co-Authored-By: Claude Opus 5.5 <[email protected]>