Skip to content

feat: Implement pdsh compatibility layer core infrastructure #97

Closed

Description

@inureyes

Summary

Implement the core infrastructure for pdsh compatibility mode, including binary name detection, environment variable support, CLI parser, and option mapping layer. This enables bssh to act as a drop-in replacement for pdsh.

Parent Issue

Part of #91 (pdsh compatibility mode) - Phase 2: Core Infrastructure

Prerequisites

This issue depends on Phase 1 options being implemented first:

Background

To make bssh a drop-in replacement for pdsh, we need:

  1. Detect when running as "pdsh" (via symlink or binary name)
  2. Support BSSH_PDSH_COMPAT environment variable
  3. Parse pdsh-style command line arguments
  4. Map pdsh options to equivalent bssh options

Proposed Implementation

1. Binary Name Detection (main.rs)

use std::env;
use std::path::Path;

fn is_pdsh_compat_mode() -> bool {
    // Check environment variable
    if env::var("BSSH_PDSH_COMPAT").map(|v| v == "1" || v == "true").unwrap_or(false) {
        return true;
    }
    
    // Check argv[0] for "pdsh"
    if let Some(arg0) = env::args().next() {
        let binary_name = Path::new(&arg0)
            .file_name()
            .and_then(|n| n.to_str())
            .unwrap_or("");
        if binary_name == "pdsh" || binary_name.starts_with("pdsh.") {
            return true;
        }
    }
    
    false
}

2. pdsh CLI Parser (src/cli/pdsh.rs)

use clap::Parser;

#[derive(Parser, Debug)]
#[command(name = "pdsh")]
pub struct PdshCli {
    #[arg(short = 'w', help = "Target hosts")]
    pub hosts: Option<String>,
    
    #[arg(short = 'x', help = "Exclude hosts")]
    pub exclude: Option<String>,
    
    #[arg(short = 'f', default_value = "32", help = "Fanout (parallel connections)")]
    pub fanout: usize,
    
    #[arg(short = 'l', help = "Login user")]
    pub user: Option<String>,
    
    #[arg(short = 't', help = "Connection timeout")]
    pub connect_timeout: Option<u64>,
    
    #[arg(short = 'u', help = "Command timeout")]
    pub command_timeout: Option<u64>,
    
    #[arg(short = 'N', help = "Disable hostname prefix")]
    pub no_prefix: bool,
    
    #[arg(short = 'b', help = "Batch mode")]
    pub batch: bool,
    
    #[arg(short = 'k', help = "Fail fast")]
    pub fail_fast: bool,
    
    #[arg(trailing_var_arg = true)]
    pub command: Vec<String>,
}

3. Option Mapping Layer

impl From<PdshCli> for Cli {
    fn from(pdsh: PdshCli) -> Self {
        Cli {
            hosts: pdsh.hosts.map(|h| parse_pdsh_hostlist(&h)),
            exclude: pdsh.exclude,
            parallel: pdsh.fanout,
            user: pdsh.user,
            connect_timeout: pdsh.connect_timeout.unwrap_or(10),
            timeout: pdsh.command_timeout.unwrap_or(0),
            no_prefix: pdsh.no_prefix,
            batch: pdsh.batch,
            fail_fast: pdsh.fail_fast,
            command_args: pdsh.command,
            ..Default::default()
        }
    }
}

Implementation Tasks

  • Add is_pdsh_compat_mode() function in main.rs
  • Create src/cli/pdsh.rs with pdsh-compatible CLI parser
  • Implement From<PdshCli> for Cli conversion
  • Add --pdsh-compat flag to bssh CLI as alternative activation
  • Wire up mode detection in main entry point
  • Add comprehensive tests for mode detection
  • Add tests for option mapping correctness
  • Update module structure (src/cli/mod.rs)

Option Mapping Table

pdsh option bssh option Notes
-w hosts -H hosts Direct mapping
-x hosts --exclude hosts Direct mapping
-f N --parallel N Direct mapping
-l user -l user Same option
-t N --connect-timeout N Direct mapping
-u N --timeout N Direct mapping
-N --no-prefix Direct mapping
-b --batch Direct mapping
-k --fail-fast Direct mapping
-q Special: dry-run Show hosts and exit
-S --any-failure Return largest exit code

Acceptance Criteria

  • Running pdsh -w hosts command works when bssh is symlinked as pdsh
  • BSSH_PDSH_COMPAT=1 bssh -w hosts command works
  • bssh --pdsh-compat -w hosts command works
  • All pdsh options map correctly to bssh equivalents
  • Unknown pdsh options produce helpful error messages
  • Normal bssh operation is completely unaffected

Notes

  • This is the main integration point for pdsh compatibility
  • Must be implemented after Phase 1 options are available
  • Consider adding a --pdsh-help to show pdsh-style help

Activity

  1. self-assigned this
    on Dec 16, 2025
  2. added and removed
    status:backlogIn the backlog, not yet ready
    on Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions