Files
devvm/testdata/script/completion.txtar
T
w3cjandClaude Opus 5.5 f9e14e9b37 feat(cli): usage errors as devvm messages, checked before anything runs, exit code 2
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]>
2026-11-01 02:27:57 -08:00

72 lines
1.8 KiB
Plaintext

# devvm completion prints a script for bash, zsh and fish, and nothing else.
exec devvm completion bash
stdout '__devvm'
! stderr .
exec devvm completion zsh
stdout '^#compdef devvm$'
exec devvm completion fish
stdout 'complete -c devvm'
env DEVVM_MESSAGES=names
! exec devvm completion powershell
stderr '^devvm: arg_not_choice choices=bash, zsh, fish command=devvm completion given=powershell$'
stderr '^usage_help command=devvm completion$'
! stdout .
# The commands users run, not the hidden ones, with image names for IMAGE.
exec devvm __complete ''
stdout '^build\t'
stdout '^completion\t'
stdout '^base$'
stdout '^claude$'
! stdout '^_'
! stdout '^version'
stdout '^:4$'
# Your layers are image names; the parts given are left out.
mkdir $XDG_CONFIG_HOME/devvm/layers
cp foo.sh $XDG_CONFIG_HOME/devvm/layers/foo.sh
exec devvm __complete build node+
stdout '^node\+foo$'
stdout '^node\+claude$'
! stdout '^node\+node$'
exec devvm __complete node+c
cmp stdout node-c.txt
# tools add and rm take shared tools only, each a word of its own, those
# given left out.
exec devvm __complete tools add ''
stdout '^python$'
! stdout '^foo$'
! stdout '^base$'
exec devvm __complete tools rm python c
stdout '^claude$'
stdout '^codex$'
! stdout python
exec devvm __complete tools add python ''
! stdout '^python$'
stdout '^claude$'
# Flags: backend names, the ports keywords; never file names.
exec devvm __complete --backend ''
stdout '^lima$'
exec devvm __complete setup --backend ''
stdout '^lima$'
exec devvm __complete setup --features fzf,
stdout '^fzf,omb$'
! stdout '^fzf,fzf$'
exec devvm __complete --ports ''
stdout '^all$'
stdout '^none$'
exec devvm __complete rm ''
stdout '^:4$'
exec devvm __complete completion ''
stdout '^fish$'
! stub_calls
-- foo.sh --
#!/bin/bash
-- node-c.txt --
node+claude
node+codex
:4