use bssh::commands::interactive::InteractiveCommand;
use bssh::config::{Config, InteractiveConfig};
use bssh::node::Node;
use bssh::pty::PtyConfig;
use bssh::ssh::known_hosts::StrictHostKeyChecking;
use bssh::ssh::tokio_client::SshConnectionConfig;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt().with_env_filter("info").init();
println!("Interactive Mode Demo");
println!("=====================");
println!();
println!("This example demonstrates how to use bssh's interactive mode programmatically.");
println!();
let nodes = vec![Node::new(
String::from("localhost"),
22,
String::from("user"),
)];
let interactive_cmd = InteractiveCommand {
single_node: true, multiplex: false,
prompt_format: String::from("[{user}@{host}:{pwd}]$ "),
history_file: PathBuf::from("~/.bssh_demo_history"),
work_dir: None,
nodes,
config: Config::default(),
interactive_config: InteractiveConfig::default(),
cluster_name: None,
key_path: None,
use_agent: false,
use_password: false,
#[cfg(target_os = "macos")]
use_keychain: false,
strict_mode: StrictHostKeyChecking::AcceptNew,
jump_hosts: None,
pty_config: PtyConfig::default(),
use_pty: None,
ssh_connection_config: SshConnectionConfig::default(),
};
println!("Starting interactive session...");
println!("Note: This will attempt to connect to localhost:22");
println!("Make sure you have SSH server running locally.");
println!();
match interactive_cmd.execute().await {
Ok(result) => {
println!("\nSession Summary:");
println!(" Duration: {:?}", result.duration);
println!(" Commands executed: {}", result.commands_executed);
println!(" Nodes connected: {}", result.nodes_connected);
}
Err(e) => {
eprintln!("Interactive session failed: {e}");
eprintln!("\nTip: To test interactive mode, try:");
eprintln!(" 1. Start a local SSH server");
eprintln!(" 2. Or use: bssh -H user@remote-host interactive");
}
}
Ok(())
}