diff --git a/scripts/land-work.sh b/scripts/land-work.sh index 2c20594ad..d21ba094b 100644 --- a/scripts/land-work.sh +++ b/scripts/land-work.sh @@ -6,6 +6,10 @@ # [--subject TEXT] [--attribution LINE] [--business ID] # [--project ID] # +# --org ID is --business ID (rename r2): each spelling once, both only with one value. A missing, +# empty or flag-shaped value exits 4 before the config is read. The id keeps its old grammar: any +# other text names businesses/.json, and a missing file exits 3. +# # Checks, in order; each refusal names its reason on stderr and exits 2: # bus-schema the bus database's schema isn't the Store's # decision-not-found no decision with that id and one raise in the business @@ -48,6 +52,9 @@ REPO="$(cd "$SCRIPT_DIR/.." && pwd)" usage() { echo "usage: land-work.sh [--base refactor] [--dry-run] [--subject TEXT] [--attribution LINE] [--business ID] [--project ID]" >&2; exit 4; } fail() { echo "land-work: $1" >&2; exit "${2:-1}"; } refuse() { echo "land-work: refused: $1${2:+: $2}" >&2; exit 2; } +# shellcheck source=scripts/selector.sh +. "$SCRIPT_DIR/selector.sh" || fail "cannot read $SCRIPT_DIR/selector.sh" 4 +lw_selector_refused() { fail "$2" 4; } DECISION=""; BASE="refactor"; DRY_RUN="no"; SUBJECT=""; ATTRIBUTION="" BUSINESS=""; PROJECT="" @@ -57,7 +64,7 @@ while [ $# -gt 0 ]; do --dry-run) DRY_RUN="yes"; shift ;; --subject) [ $# -ge 2 ] || usage; SUBJECT="$2"; shift 2 ;; --attribution) [ $# -ge 2 ] || usage; ATTRIBUTION="$2"; shift 2 ;; - --business) [ $# -ge 2 ] || usage; BUSINESS="$2"; shift 2 ;; + --business|--org) selector_take args id lw_selector_refused - "$1" "${@:2:1}"; BUSINESS="$2"; shift 2 ;; --project) [ $# -ge 2 ] || usage; PROJECT="$2"; shift 2 ;; -*) usage ;; *) [ -z "$DECISION" ] || usage; DECISION="$1"; shift ;; diff --git a/scripts/test-land-work.sh b/scripts/test-land-work.sh index d689e0e14..e78055943 100644 --- a/scripts/test-land-work.sh +++ b/scripts/test-land-work.sh @@ -242,6 +242,46 @@ cp "$SANDBOX/c/args/businesses/fx.json" "$SANDBOX/c/nobus/businesses/" sed "s#$SANDBOX/c/args/data#$SANDBOX/c/nobus/data#" "$SANDBOX/c/args/config.json" > "$SANDBOX/c/nobus/config.json" expect nobus 3 "" "$D" +# ---- rename r2: --org is --business, each spelling once ---- +# Against a missing config: exit 4 and the message mean the parse refused before any read (3 otherwise). +sel() { # want-rc want-stderr args... + local want="$1" text="$2" rc=0 err + shift 2 + err="$(MOSAIC_CONFIG="$SANDBOX/missing.json" TMPDIR="$SANDBOX/c/args/tmp" bash scripts/land-work.sh "$@" 2>&1 >/dev/null)" || rc=$? + check "selector: $* exits $want: $text (got $rc: $err)" "$([ "$rc" -eq "$want" ] && [ "$err" = "$text" ]; echo $?)" +} +sel 4 "land-work: --business fx and --org other conflict" "$D" --business fx --org other +sel 4 "land-work: --org other and --business fx conflict" "$D" --org other --business fx +sel 4 "land-work: --business given twice" "$D" --business fx --business fx +sel 4 "land-work: --org given twice" "$D" --org fx --org fx +sel 4 "land-work: --org given twice" "$D" --org fx --business fx --org fx +sel 4 "land-work: --org needs one value" "$D" --org +sel 4 "land-work: --business needs one value" "$D" --business "" +sel 4 "land-work: --org needs one value, not --dry-run" "$D" --org --dry-run +sel 4 "land-work: --business needs one value, not -fx" "$D" --business -fx +USAGE="$(bash scripts/land-work.sh 2>&1)" +sel 4 "$USAGE" --org fx +sel 4 "$USAGE" "$D" --org fx extra +# A value another option takes is text, not a selector: the config read is what refuses. +rc=0; err="$(MOSAIC_CONFIG="$SANDBOX/missing.json" TMPDIR="$SANDBOX/c/args/tmp" bash scripts/land-work.sh "$D" --subject --org 2>&1 >/dev/null)" || rc=$? +check "selector: --subject --org is a subject, and the config read refuses (got $rc)" \ + "$([ "$rc" -eq 3 ] && [ "${err##*$'\n'}" = "land-work: system config is missing or invalid" ]; echo $?)" +# Each spelling alone and both together name the business file read. +# land-work never had an id grammar and keeps none, so text that is not an id is a missing file too. +for args in "--business other" "--org other" "--org other --business other" "--org Other" "--business ../other"; do + # shellcheck disable=SC2086 + expect args 3 "" "$D" $args + check "selector: $args names businesses/${args##* }.json" \ + "$([ "$(tail -n1 "$SANDBOX/c/args/err")" = "land-work: no business file: $SANDBOX/c/args/businesses/${args##* }.json" ]; echo $?)" +done +expect args 2 decision-not-found "d0000000-0000-4000-8000-00000000000f" --org fx +expect args 2 decision-not-found "d0000000-0000-4000-8000-00000000000f" --business fx --org fx +expect args 2 decision-not-found "d0000000-0000-4000-8000-00000000000f" --org fx --business fx +setup dry-org ok 42 "$W_OK" +expect dry-org 0 "" "$D" --dry-run --org fx +grep -q "no ref was written" "$SANDBOX/c/dry-org/out" +check "selector: --org fx runs the dry run" "$?" + # ---- the bus database ---- setup schema-table ok 42 "$W_OK" node -e 'const {DatabaseSync}=require("node:sqlite"); const db=new DatabaseSync(process.argv[1]); db.exec("CREATE TABLE extra(x)"); db.close()' \