Skip to content

feat: Add --batch option for single Ctrl+C termination (pdsh -b compatibility)#102

Merged
inureyes merged 3 commits intomainfrom
feature/issue-95-batch-mode-ctrl-c
Dec 16, 2025
Merged

feat: Add --batch option for single Ctrl+C termination (pdsh -b compatibility)#102
inureyes merged 3 commits intomainfrom
feature/issue-95-batch-mode-ctrl-c

Conversation

@inureyes
Copy link
Member

Summary

Implements --batch / -b option that changes Ctrl+C behavior to immediately terminate all parallel jobs with a single press. This improves automation and CI/CD integration by providing immediate termination without requiring confirmation.

Changes

Core Implementation

  • CLI Interface (src/cli.rs): Added --batch / -b flag with help text
  • Parameter Passing (src/app/dispatcher.rs, src/commands/exec.rs): Pass batch flag through ExecuteCommandParams to ParallelExecutor
  • Signal Handling (src/executor/parallel.rs):
    • Implemented two-stage Ctrl+C handling in stream mode
    • Default: First Ctrl+C shows status, second terminates (within 1s)
    • Batch mode: Single Ctrl+C immediately terminates all jobs
  • TUI Integration (src/ui/tui/mod.rs): Updated signature to accept batch parameter (reserved for future use)

Documentation

  • CLI Help: Added batch mode examples in after_help section
  • README.md: New "Batch Mode (Ctrl+C Handling)" section with usage examples
  • ARCHITECTURE.md: Documented signal handling implementation details

Behavior

Default Mode (Two-Stage Ctrl+C)

bssh -C production "long-running-command"
# Ctrl+C once: shows "Status: X running, Y completed"
# Ctrl+C again (within 1s): terminates all jobs

Batch Mode (Immediate Termination)

bssh -C production -b "long-running-command"
# Ctrl+C once: immediately terminates all jobs

Compatibility

This feature provides pdsh -b compatibility, making it easier for users migrating from pdsh to bssh.

Testing

  • ✅ Code compiles successfully in both debug and release modes
  • ✅ CLI help displays --batch option correctly
  • ⚠️ Integration tests for signal handling are deferred (requires interactive testing framework)

Test Plan

Manual testing should verify:

  1. Default mode: First Ctrl+C shows status, second terminates
  2. Batch mode: Single Ctrl+C immediately terminates
  3. Works correctly in TUI, stream, and normal modes
  4. Exit codes reflect signal termination appropriately

Closes #95

@inureyes inureyes added type:enhancement New feature or request priority:medium Medium priority issue pdsh-compat pdsh compatibility mode features status:review Under review labels Dec 16, 2025
inureyes added a commit that referenced this pull request Dec 16, 2025
This commit fixes all HIGH and MEDIUM severity issues identified in PR #102 review:

HIGH SEVERITY FIXES:

1. Signal Handler Race Condition - Time Window Reset Logic Bug
   - Fixed: When time window expires (>1 second) and user presses Ctrl+C again,
     the code now displays running/completed status in the reset path
   - Location: src/executor/parallel.rs lines 701-713 (stream mode)
   - Impact: Consistent user experience across all Ctrl+C press scenarios

2. Inconsistent Signal Handling Across Execution Modes
   - Fixed: Added complete signal handling to normal execute() method
   - Previously only handle_stream_mode() had signal handling
   - Location: src/executor/parallel.rs lines 172-280 (execute method)
   - Impact: Batch mode and two-stage Ctrl+C now work in all execution modes

MEDIUM SEVERITY FIXES:

3. Missing Exit Code Handling After Signal Termination
   - Fixed: All signal terminations now exit with code 130 (SIGINT standard)
   - Applied to both batch and non-batch modes in all execution paths
   - Location: Multiple locations in src/executor/parallel.rs
   - Impact: Scripts can now distinguish user interruption from command failure

4. No Documentation Conflict Warning for TUI Mode
   - Fixed: Updated CLI help text to clarify TUI mode ignores batch flag
   - Location: src/cli.rs line 103
   - Impact: Clear user expectations for TUI mode behavior

5. Documentation Mismatch in ARCHITECTURE.md
   - Fixed: Updated pseudocode and documentation to match actual implementation
   - Added exit code handling details and implementation coverage notes
   - Location: ARCHITECTURE.md lines 303-394
   - Impact: Accurate documentation for future maintainers

TESTING:
- All tests pass (cargo test)
- No clippy warnings (cargo clippy -- -D warnings)
- Code properly formatted (cargo fmt --check)

Changes:
- ARCHITECTURE.md: Updated signal handling documentation with accurate pseudocode
- src/cli.rs: Added TUI mode note to batch flag help text
- src/executor/parallel.rs: Added signal handling to execute(), fixed reset path status display, added exit code 130
inureyes added a commit that referenced this pull request Dec 16, 2025
…ions

This commit adds proper Ctrl+C signal handling to all file transfer methods
and the file output mode handler:

- upload_file: Added tokio::select! with two-stage Ctrl+C handling
- download_file: Added tokio::select! with two-stage Ctrl+C handling
- download_files: Added tokio::select! with two-stage Ctrl+C handling
- handle_file_mode: Refactored from simple while loop to tokio::select! pattern

All methods now support:
- Batch mode: Single Ctrl+C immediately terminates with exit code 130
- Non-batch mode: First Ctrl+C shows status, second terminates
- Proper abort of pending task handles on termination
- Status reporting showing running/completed task counts

These changes complete the signal handling improvements from PR #102,
ensuring all parallel execution paths can be gracefully interrupted.
@inureyes inureyes self-assigned this Dec 16, 2025
…tibility)

Add --batch / -b option that changes Ctrl+C behavior to immediately terminate
all parallel jobs with a single press. This improves automation and CI/CD
integration by providing immediate termination without requiring confirmation.

Changes:
- Add --batch / -b CLI flag to Cli struct
- Pass batch flag through ExecuteCommandParams to ParallelExecutor
- Implement two-stage Ctrl+C handling in stream mode:
  * Default: First Ctrl+C shows status, second terminates (within 1s)
  * Batch mode: Single Ctrl+C immediately terminates all jobs
- Update TUI mode signature to accept batch parameter (reserved for future use)
- Add CLI help examples for batch mode usage
- Update README.md with Batch Mode section and examples
- Document signal handling implementation in ARCHITECTURE.md

The default behavior provides visibility into execution progress before termination,
while batch mode is optimized for scripts and non-interactive environments.

Implements: #95
This commit fixes all HIGH and MEDIUM severity issues identified in PR #102 review:

HIGH SEVERITY FIXES:

1. Signal Handler Race Condition - Time Window Reset Logic Bug
   - Fixed: When time window expires (>1 second) and user presses Ctrl+C again,
     the code now displays running/completed status in the reset path
   - Location: src/executor/parallel.rs lines 701-713 (stream mode)
   - Impact: Consistent user experience across all Ctrl+C press scenarios

2. Inconsistent Signal Handling Across Execution Modes
   - Fixed: Added complete signal handling to normal execute() method
   - Previously only handle_stream_mode() had signal handling
   - Location: src/executor/parallel.rs lines 172-280 (execute method)
   - Impact: Batch mode and two-stage Ctrl+C now work in all execution modes

MEDIUM SEVERITY FIXES:

3. Missing Exit Code Handling After Signal Termination
   - Fixed: All signal terminations now exit with code 130 (SIGINT standard)
   - Applied to both batch and non-batch modes in all execution paths
   - Location: Multiple locations in src/executor/parallel.rs
   - Impact: Scripts can now distinguish user interruption from command failure

4. No Documentation Conflict Warning for TUI Mode
   - Fixed: Updated CLI help text to clarify TUI mode ignores batch flag
   - Location: src/cli.rs line 103
   - Impact: Clear user expectations for TUI mode behavior

5. Documentation Mismatch in ARCHITECTURE.md
   - Fixed: Updated pseudocode and documentation to match actual implementation
   - Added exit code handling details and implementation coverage notes
   - Location: ARCHITECTURE.md lines 303-394
   - Impact: Accurate documentation for future maintainers

TESTING:
- All tests pass (cargo test)
- No clippy warnings (cargo clippy -- -D warnings)
- Code properly formatted (cargo fmt --check)

Changes:
- ARCHITECTURE.md: Updated signal handling documentation with accurate pseudocode
- src/cli.rs: Added TUI mode note to batch flag help text
- src/executor/parallel.rs: Added signal handling to execute(), fixed reset path status display, added exit code 130
…ions

This commit adds proper Ctrl+C signal handling to all file transfer methods
and the file output mode handler:

- upload_file: Added tokio::select! with two-stage Ctrl+C handling
- download_file: Added tokio::select! with two-stage Ctrl+C handling
- download_files: Added tokio::select! with two-stage Ctrl+C handling
- handle_file_mode: Refactored from simple while loop to tokio::select! pattern

All methods now support:
- Batch mode: Single Ctrl+C immediately terminates with exit code 130
- Non-batch mode: First Ctrl+C shows status, second terminates
- Proper abort of pending task handles on termination
- Status reporting showing running/completed task counts

These changes complete the signal handling improvements from PR #102,
ensuring all parallel execution paths can be gracefully interrupted.
@inureyes inureyes force-pushed the feature/issue-95-batch-mode-ctrl-c branch from 06b7115 to c0fe704 Compare December 16, 2025 15:06
@inureyes inureyes merged commit 290741e into main Dec 16, 2025
1 of 2 checks passed
@inureyes inureyes deleted the feature/issue-95-batch-mode-ctrl-c branch December 16, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pdsh-compat pdsh compatibility mode features priority:medium Medium priority issue status:review Under review type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add --batch option for single Ctrl+C termination (pdsh -b compatibility)

1 participant