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:
- Detect when running as "pdsh" (via symlink or binary name)
- Support
BSSH_PDSH_COMPAT environment variable
- Parse pdsh-style command line arguments
- 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
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
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
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:
--excludeoption--no-prefixoption--batchoption--fail-fastoption--connect-timeoutoption (TBD)Background
To make bssh a drop-in replacement for pdsh, we need:
BSSH_PDSH_COMPATenvironment variableProposed Implementation
1. Binary Name Detection (
main.rs)2. pdsh CLI Parser (
src/cli/pdsh.rs)3. Option Mapping Layer
Implementation Tasks
is_pdsh_compat_mode()function inmain.rssrc/cli/pdsh.rswith pdsh-compatible CLI parserFrom<PdshCli> for Cliconversion--pdsh-compatflag to bssh CLI as alternative activationsrc/cli/mod.rs)Option Mapping Table
-w hosts-H hosts-x hosts--exclude hosts-f N--parallel N-l user-l user-t N--connect-timeout N-u N--timeout N-N--no-prefix-b--batch-k--fail-fast-q-S--any-failureAcceptance Criteria
pdsh -w hosts commandworks when bssh is symlinked as pdshBSSH_PDSH_COMPAT=1 bssh -w hosts commandworksbssh --pdsh-compat -w hosts commandworksNotes
--pdsh-helpto show pdsh-style help