Skip to content

fix(argv): -h/--help intercept on cmd_part (was actually parting on --help) - #236

Merged
joelteply merged 1 commit into
canaryfrom
fix/help-flag-intercept-on-cmd-part-too
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/help-flag-intercept-on-cmd-part-too

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Same anti-pattern as #231 fixed for cmd_send/kick/whois, missed in cmd_part. 'airc part --help' was actually executing /part and disconnecting the monitor. Now intercepts -h/--help before state mutation.

Verification: tabs 19/0, room 14/0; manual.

…--help

Same anti-pattern as #231 fixed for cmd_send / cmd_kick / cmd_whois,
missed in cmd_part. Found the hard way 2026-04-28 by airc-96dd
during follow-up testing: ran 'airc part --help' to check the help
text, the --help fell through, cmd_part treated it as "no specific
channel" and parted the current room — disconnecting the monitor.

## Fix

cmd_rooms.sh::cmd_part: case statement intercepting -h / --help
BEFORE ensure_init or any state mutation. Prints usage describing
the host vs joiner branches.

## Verification

  bash -n: clean
  Manual: 'airc part --help' / 'airc part -h' both print usage
          without touching scope state.
  test/integration.sh tabs: 19/0 ✓
  test/integration.sh room: 14/0 ✓

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 28, 2026 19:28
@joelteply
joelteply merged commit eead4f3 into canary Apr 28, 2026
1 check passed
@joelteply
joelteply deleted the fix/help-flag-intercept-on-cmd-part-too branch April 28, 2026 19:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a CLI UX/safety bug where airc part --help (or -h) would fall through argument parsing and actually execute a /part, mutating state and disconnecting the monitor.

Changes:

  • Add an early -h|--help intercept in cmd_part() before ensure_init / state mutation.
  • Print cmd_part usage text and exit cleanly when help is requested.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

echo "Usage:"
echo " airc part leave the current channel (host's gist deleted if you're host)"
echo " (joiner: just local teardown; host's gist stays for others)"
echo " airc part --no-teardown clear room state but don't kill the airc process"
Comment on lines +193 to +206
# Help-flag intercept BEFORE ensure_init / state mutation. Without
# this, `airc part --help` (and `-h`) fell through and ACTUALLY
# PARTED the user's current room — found the hard way 2026-04-28
# by airc-96dd while exercising the --help-intercept follow-up
# work from #231. Same anti-pattern as the cmd_send/kick/whois
# bugs that #231 already fixed; cmd_part was missed.
case "${1:-}" in
-h|--help)
echo "Usage:"
echo " airc part leave the current channel (host's gist deleted if you're host)"
echo " (joiner: just local teardown; host's gist stays for others)"
echo " airc part --no-teardown clear room state but don't kill the airc process"
return 0 ;;
esac
joelteply added a commit that referenced this pull request Apr 28, 2026
…ep) (#237)

fix(argv): -h/--help intercept on all remaining cmd_X — class-wide sweep

Verb-fuzz from vhsm-d1f4 + continuum-b741 + ideem-local-4bef on 2026-04-28
caught the same anti-pattern as #231/#236 in additional verbs:

  DESTRUCTIVE on --help (mutated state):
    airc away --help     → set status to "--help"
    airc reminder --help → wrote "--help" as the reminder interval
    airc channel --help  → set channel preference to "--help"
                           (would brick next 'airc update'!)

  NON-DESTRUCTIVE but no help text:
    airc status --help, airc connect --help, airc teardown --help,
    airc daemon --help, airc doctor --help, airc update --help

## Fix

Class-wide sweep: every cmd_X (and key helpers) now intercepts -h/--help
BEFORE state mutation and prints a real usage block. Also added
defense-in-depth in cmd_channel and cmd_reminder:

  - cmd_channel: refuses any flag-shaped value (case "$target" in -*)
  - cmd_reminder: refuses non-numeric arg (catches --foo, --bar etc)

These guard against the same class of bug for flags we don't enumerate.

## Coverage

After this PR: every cmd_X in lib/airc_bash/ has a -h/--help intercept.
Audit: `for f in lib/airc_bash/cmd_*.sh; do grep -qE -- "-h\\|--help" "$f"
|| echo "MISSING: $f"; done` returns nothing.

## Verification

  bash -n on all 8 changed files: clean
  Manual: airc {reminder,channel,away,connect,doctor,daemon,update,status,
          teardown} --help all print usage; none mutate.
  test/integration.sh tabs:                    19/0 ✓
  test/integration.sh room:                    14/0 ✓
  test/integration.sh general_sidecar_default: 10/0 ✓
  test/integration.sh away:                    5/0  ✓

## Bug pattern + future hardening

The recurring shape: bash function takes positional arg, doesn't validate
it, writes it to a state file as the new value. Anyone running `cmd --help`
expecting usage gets state mutation instead. Three fixes share design:
  1. -h/--help intercept BEFORE any state-touching code
  2. Reject flag-shaped tokens (-*) when the value should be a name/number
  3. Default action prints help, not "save whatever was passed"

Worth porting (1) + (2) to airc.ps1 too — same shape, untested.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants