diff --git a/party b/party index 17f676d..f8a08a3 100755 --- a/party +++ b/party @@ -635,6 +635,26 @@ pick_live_party() { eval "roster_read \"\$$pick\"" } +# Resolve the party a join or knock targets: the named party if given, +# else the single live party (or a numbered prompt via pick_live_party). +# Sets RR_* on success; exits 1 with the appropriate message otherwise. +resolve_joinable_party() { + _rj_name="$1" + if [ -n "$_rj_name" ]; then + # Capture rc explicitly: under set -e a bare `find_party_by_name` + # returning 1 or 2 would exit before the case ran, swallowing the + # error message. + find_party_by_name "$_rj_name" && rc=0 || rc=$? + case $rc in + 0) ;; + 1) echo "party: '$_rj_name' not found." >&2; exit 1 ;; + 2) exit 1 ;; # find_party_by_name already printed the ambiguity hint + esac + else + pick_live_party || exit 1 + fi +} + # Subcommand dispatch # =================== @@ -1189,19 +1209,7 @@ EOF exit 1 fi - if [ -n "$name" ]; then - # Capture rc explicitly: under set -e a bare `find_party_by_name` - # returning 1 or 2 would exit before the case ran, swallowing the - # error message. - find_party_by_name "$name" && rc=0 || rc=$? - case $rc in - 0) ;; - 1) echo "party: '$name' not found." >&2; exit 1 ;; - 2) exit 1 ;; # find_party_by_name already printed the ambiguity hint - esac - else - pick_live_party || exit 1 - fi + resolve_joinable_party "$name" # Group gate. Check membership against the party's *recorded* group # (RR_GROUP), the host may have hosted under --group . The @@ -1355,16 +1363,7 @@ EOF esac done - if [ -n "$name" ]; then - find_party_by_name "$name" && rc=0 || rc=$? - case $rc in - 0) ;; - 1) echo "party: '$name' not found." >&2; exit 1 ;; - 2) exit 1 ;; # find_party_by_name printed the ambiguity hint - esac - else - pick_live_party || exit 1 - fi + resolve_joinable_party "$name" if [ "$RR_HOST_USER" = "$USER" ]; then echo "party knock: '$RR_PARTY_NAME' is your own party." >&2