0
0
#!/usr/bin/env bash
# The CLI argument checker (plan 0043). A binary of this tree:
# - answers --help for every verb of verbApps (cmd/socialweb-computer/main.go) and every verb that runs a command (it
# fails when internal/clicfg/options.json and deploy/apps/option-map.yaml define one name twice), and each command
# verb's help shows the `--exec -- <command> [args...]` form;
# - parses every unit template's ExecStart with `internal parse-args` (at least one is parsed).
# And no tracked text carries an old form: options after `--` in a unit, a drop-in or the cloud-init texts; `--exec`
# with a value in the tests, scripts and rust/; ` -- --<option>` after a socialweb-computer command in the docs that
# describe today (plans, acceptance runs, research and ARCHITECTURE history excluded).
# scripts/check-cli-args.sh
set -uo pipefail
cd "$(dirname "$0")/.."
mkdir -p "${TMPDIR:-$HOME/.tmp}"
dir="$(mktemp -d "${TMPDIR:-$HOME/.tmp}/check-cli-args.XXXXXX")" || exit 2
trap 'rm -rf "$dir"' EXIT
rc=0
bad() { echo "check-cli-args: FAIL $*" >&2; rc=1; }
b="$dir/socialweb-computer"
go build -o "$b" ./cmd/socialweb-computer || { echo "check-cli-args: go build failed" >&2; exit 1; }
apps="$(sed -n '/^var verbApps = map\[string\]string{$/,/^}$/s/^[[:space:]]*"\([^"]*\)":.*/\1/p' cmd/socialweb-computer/main.go)"
[ "$(wc -l <<<"$apps")" -ge 5 ] || bad "found $(wc -l <<<"$apps") verbs in verbApps of cmd/socialweb-computer/main.go (want 5 or more: the parse of the map broke)"
execs=("run request" "run request resume" "run request ssh" "run requester ssh")
verbs=0
while IFS= read -r verb; do
[ -n "$verb" ] || continue
verbs=$((verbs + 1))
# shellcheck disable=SC2086
out="$("$b" $verb --help 2>&1)" || bad "$verb --help: $(grep -v '^ ' <<<"$out" | head -3)"
done < <(printf '%s\n' "$apps" "${execs[@]}" | sort -u)
for verb in "${execs[@]}"; do
# shellcheck disable=SC2086
"$b" $verb --help 2>&1 | grep -qF -- 'usage: socialweb-computer '"$verb"' [options] --exec -- <command> [args...]' ||
bad "$verb --help does not show its --exec -- <command> [args...] form"
done
units=0
for unit in internal/install/templates/*.service; do
while IFS= read -r line; do
args="${line#*socialweb-computer }"
args="${args//%i/h.test}"
units=$((units + 1))
# shellcheck disable=SC2086
out="$("$b" internal parse-args $args 2>&1 >/dev/null)" || bad "$unit: $line: $out"
done < <(grep -E '^ExecStart=.*socialweb-computer ' "$unit")
done
[ "$units" -ge 1 ] || bad "parsed no ExecStart of internal/install/templates/*.service"
old() {
local what="$1" pattern="$2"; shift 2
local hits code
hits="$(git grep -n -E -e "$pattern" -- "$@")"
code=$?
[ "$code" -le 1 ] || { bad "git grep for $what exited $code"; return; }
hits="$(grep -v -E -e '--exec (and|takes|runs|with|is|on|of) ' -e 'cargo (test|run)[^`]* -- --' -e 'set -- --' <<<"$hits" | grep -v '^$')"
[ -z "$hits" ] || { echo "$hits" >&2; bad "$what (-- ends the options, --exec takes no value: plan 0043)"; }
}
old "options after -- in a unit or a drop-in" 'ExecStart=[^`]*socialweb-computer [^`]* -- ' \
':!docs/plans/' ':!docs/research/' ':!docs/ARCHITECTURE.md' ':!docs/2026-*' ':!docs/acceptance/' ':!NEXT.yaml' ':!scripts/check-cli-args.sh'
old "options after -- in a cloud-init or install text" ' -- --' -- internal/install/templates internal/atproto/cloudinit internal/guestseed internal/guestagent
old "--exec with a value in a test, a script or rust/" '--exec[= ]+(\\?["'"'"']|[a-zA-Z/$])' -- tests scripts rust infra deploy ':!scripts/check-cli-args.sh'
old "options after -- after a socialweb-computer command in the docs" \
'(socialweb-computer|run (request|requester|bidder)|run gateway ssh|install requester)( [^|;&`]*)? -- --[a-z]' \
-- '*.md' '*.yaml' ':!docs/plans/' ':!docs/research/' ':!docs/ARCHITECTURE.md' ':!docs/2026-*' ':!docs/acceptance/' ':!NEXT.yaml' ':!docs/design/'
[ "$rc" = 0 ] && echo "check-cli-args: ok ($verbs verbs, $units unit ExecStart lines parsed, no old form)"
exit "$rc"