fix: [nomad-step-0] S0.1-fix — bin/disinto swallows --backend=nomad as repo_url positional (#835) #839
2 changed files with 60 additions and 6 deletions
27
bin/disinto
27
bin/disinto
|
|
@ -707,13 +707,18 @@ _disinto_init_nomad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
disinto_init() {
|
disinto_init() {
|
||||||
local repo_url="${1:-}"
|
# Only consume $1 as repo_url if it looks like a positional arg (not a
|
||||||
if [ -z "$repo_url" ]; then
|
# flag). The nomad backend (#835) takes no positional — the LXC already
|
||||||
echo "Error: repo URL required" >&2
|
# has the repo cloned by the operator, and repo_url is a docker-backend
|
||||||
echo "Usage: disinto init <repo-url>" >&2
|
# concept. Eagerly consuming `--backend=nomad` as repo_url produced the
|
||||||
exit 1
|
# nonsense "--empty is only valid with --backend=nomad" error seen in
|
||||||
|
# S0.1 end-to-end testing on a fresh LXC. Defer the "repo URL required"
|
||||||
|
# check to after argparse, where we know the backend.
|
||||||
|
local repo_url=""
|
||||||
|
if [ $# -gt 0 ] && [[ "$1" != --* ]]; then
|
||||||
|
repo_url="$1"
|
||||||
|
shift
|
||||||
fi
|
fi
|
||||||
shift
|
|
||||||
|
|
||||||
# Parse flags
|
# Parse flags
|
||||||
local branch="" repo_root="" ci_id="0" auto_yes=false forge_url_flag="" bare=false rotate_tokens=false use_build=false dry_run=false backend="docker" empty=false
|
local branch="" repo_root="" ci_id="0" auto_yes=false forge_url_flag="" bare=false rotate_tokens=false use_build=false dry_run=false backend="docker" empty=false
|
||||||
|
|
@ -741,6 +746,16 @@ disinto_init() {
|
||||||
*) echo "Error: invalid --backend value '${backend}' (expected: docker|nomad)" >&2; exit 1 ;;
|
*) echo "Error: invalid --backend value '${backend}' (expected: docker|nomad)" >&2; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# Docker backend requires a repo_url positional; nomad doesn't use one.
|
||||||
|
# This check must run *after* argparse so `--backend=docker` (with no
|
||||||
|
# positional) errors with a helpful message instead of the misleading
|
||||||
|
# "Unknown option: --backend=docker".
|
||||||
|
if [ "$backend" = "docker" ] && [ -z "$repo_url" ]; then
|
||||||
|
echo "Error: repo URL required" >&2
|
||||||
|
echo "Usage: disinto init <repo-url> [options]" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# --empty is nomad-only today (the docker path has no concept of an
|
# --empty is nomad-only today (the docker path has no concept of an
|
||||||
# "empty cluster"). Reject explicitly rather than letting it silently
|
# "empty cluster"). Reject explicitly rather than letting it silently
|
||||||
# do nothing on --backend=docker.
|
# do nothing on --backend=docker.
|
||||||
|
|
|
||||||
|
|
@ -104,3 +104,42 @@ setup_file() {
|
||||||
[ "$status" -ne 0 ]
|
[ "$status" -ne 0 ]
|
||||||
[[ "$output" == *"--empty is only valid with --backend=nomad"* ]]
|
[[ "$output" == *"--empty is only valid with --backend=nomad"* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ── Positional vs flag-first invocation (#835) ───────────────────────────────
|
||||||
|
#
|
||||||
|
# Before the #835 fix, disinto_init eagerly consumed $1 as repo_url *before*
|
||||||
|
# argparse ran. That swallowed `--backend=nomad` as a repo_url and then
|
||||||
|
# complained that `--empty` required a nomad backend — the nonsense error
|
||||||
|
# flagged during S0.1 end-to-end verification. The cases below pin the CLI
|
||||||
|
# to the post-fix contract: the nomad path accepts flag-first invocation,
|
||||||
|
# the docker path still errors helpfully on a missing repo_url.
|
||||||
|
|
||||||
|
@test "disinto init --backend=nomad --empty --dry-run (no positional) dispatches to nomad" {
|
||||||
|
run "$DISINTO_BIN" init --backend=nomad --empty --dry-run
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"nomad backend: --empty (cluster-up only, no jobs)"* ]]
|
||||||
|
[[ "$output" == *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
||||||
|
# The bug symptom must be absent — backend was misdetected as docker
|
||||||
|
# when --backend=nomad got swallowed as repo_url.
|
||||||
|
[[ "$output" != *"--empty is only valid with --backend=nomad"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "disinto init --backend nomad --dry-run (space-separated, no positional) dispatches to nomad" {
|
||||||
|
run "$DISINTO_BIN" init --backend nomad --dry-run
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"nomad backend: default"* ]]
|
||||||
|
[[ "$output" == *"[dry-run] Step 1/9: install nomad + vault binaries"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "disinto init (no args) still errors with 'repo URL required'" {
|
||||||
|
run "$DISINTO_BIN" init
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"repo URL required"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "disinto init --backend=docker (no positional) errors with 'repo URL required', not 'Unknown option'" {
|
||||||
|
run "$DISINTO_BIN" init --backend=docker
|
||||||
|
[ "$status" -ne 0 ]
|
||||||
|
[[ "$output" == *"repo URL required"* ]]
|
||||||
|
[[ "$output" != *"Unknown option"* ]]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue