fix: consistent usage errors for list, leave, status, who, log
list ignored --help and listed parties; leave and status ignored stray arguments; who silently kept the last of several positionals; log took a positional name that neither its usage nor the man page documents. All now follow the parser convention of the other subcommands: help on -h, exit 2 on an unknown flag or unexpected argument.
This commit is contained in:
parent
9b85485ee8
commit
698fff91ee
2 changed files with 43 additions and 10 deletions
31
party
31
party
|
|
@ -1090,10 +1090,7 @@ Usage: party log [--stop] [--party <name>]
|
||||||
EOF
|
EOF
|
||||||
exit 0 ;;
|
exit 0 ;;
|
||||||
-*) echo "party log: unknown flag '$1'" >&2; exit 2 ;;
|
-*) echo "party log: unknown flag '$1'" >&2; exit 2 ;;
|
||||||
*)
|
*) echo "party log: unexpected arg '$1'" >&2; exit 2 ;;
|
||||||
if [ -z "$partyname" ]; then partyname="$1"; shift
|
|
||||||
else echo "party log: unexpected arg '$1'" >&2; exit 2; fi
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -1277,10 +1274,22 @@ EOF
|
||||||
# the socket path.
|
# the socket path.
|
||||||
exec "$PARTY_TMUX" -S "$RR_SOCKET" "$@"
|
exec "$PARTY_TMUX" -S "$RR_SOCKET" "$@"
|
||||||
}
|
}
|
||||||
cmd_leave() {
|
|
||||||
|
# Argv check for the subcommands that take no arguments. $1 = label.
|
||||||
|
# A stray word is more likely a typo'd subcommand line than something
|
||||||
|
# to ignore, so it is a usage error like everywhere else.
|
||||||
|
_parse_no_args() {
|
||||||
|
label="$1"; shift
|
||||||
case "${1:-}" in
|
case "${1:-}" in
|
||||||
-h|--help) echo "Usage: party leave"; exit 0 ;;
|
'') ;;
|
||||||
|
-h|--help) echo "Usage: party $label"; exit 0 ;;
|
||||||
|
-*) echo "party $label: unknown flag '$1'" >&2; exit 2 ;;
|
||||||
|
*) echo "party $label: unexpected arg '$1'" >&2; exit 2 ;;
|
||||||
esac
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd_leave() {
|
||||||
|
_parse_no_args leave "$@"
|
||||||
|
|
||||||
# Walk every live party; for each one we have any presence on
|
# Walk every live party; for each one we have any presence on
|
||||||
# (either via __party_guest_$USER or as a client of the host's
|
# (either via __party_guest_$USER or as a client of the host's
|
||||||
|
|
@ -1520,6 +1529,7 @@ cmd_detach() {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_list() {
|
cmd_list() {
|
||||||
|
_parse_no_args list "$@"
|
||||||
found=0 lines='' first_group='' mixed=0
|
found=0 lines='' first_group='' mixed=0
|
||||||
for rec in $(roster_list); do
|
for rec in $(roster_list); do
|
||||||
roster_read "$rec" || continue
|
roster_read "$rec" || continue
|
||||||
|
|
@ -1583,7 +1593,10 @@ cmd_who() {
|
||||||
echo "Usage: party who [--short] [--party name|--socket path]"
|
echo "Usage: party who [--short] [--party name|--socket path]"
|
||||||
exit 0 ;;
|
exit 0 ;;
|
||||||
-*) echo "party who: unknown flag '$1'" >&2; exit 2 ;;
|
-*) echo "party who: unknown flag '$1'" >&2; exit 2 ;;
|
||||||
*) partyname="$1"; shift ;;
|
*)
|
||||||
|
if [ -z "$partyname" ]; then partyname="$1"; shift
|
||||||
|
else echo "party who: unexpected arg '$1'" >&2; exit 2; fi
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -1636,9 +1649,7 @@ cmd_who() {
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_status() {
|
cmd_status() {
|
||||||
case "${1:-}" in
|
_parse_no_args status "$@"
|
||||||
-h|--help) echo "Usage: party status"; exit 0 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
hosting='' joined=''
|
hosting='' joined=''
|
||||||
for rec in $(roster_list); do
|
for rec in $(roster_list); do
|
||||||
|
|
|
||||||
|
|
@ -31,3 +31,25 @@ teardown() { teardown_party_sandbox; }
|
||||||
# assertion is the test.
|
# assertion is the test.
|
||||||
[ -n "${PARTY_VERSION:-}" ]
|
[ -n "${PARTY_VERSION:-}" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "no-argument subcommands print help and reject stray args" {
|
||||||
|
for sub in list leave status; do
|
||||||
|
run "$PARTY_BIN" "$sub" --help
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == "Usage: party $sub" ]]
|
||||||
|
run "$PARTY_BIN" "$sub" stray
|
||||||
|
[ "$status" -eq 2 ]
|
||||||
|
[[ "$output" == *"unexpected arg 'stray'"* ]]
|
||||||
|
run "$PARTY_BIN" "$sub" --bogus
|
||||||
|
[ "$status" -eq 2 ]
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "who rejects a second positional, log rejects any" {
|
||||||
|
run "$PARTY_BIN" who one two
|
||||||
|
[ "$status" -eq 2 ]
|
||||||
|
[[ "$output" == *"unexpected arg 'two'"* ]]
|
||||||
|
run "$PARTY_BIN" log one
|
||||||
|
[ "$status" -eq 2 ]
|
||||||
|
[[ "$output" == *"unexpected arg 'one'"* ]]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue