-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinteractive_demo.rs
More file actions
89 lines (80 loc) · 3.08 KB
/
interactive_demo.rs
File metadata and controls
89 lines (80 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2025 Lablup Inc. and Jeongkyu Shin
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Example demonstrating interactive mode usage with bssh
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<()> {
// Initialize logging
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!();
// Create sample nodes
let nodes = vec![Node::new(
String::from("localhost"),
22,
String::from("user"),
)];
// Create interactive command configuration
let interactive_cmd = InteractiveCommand {
single_node: true, // Use single-node mode for this demo
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,
ssh_password: None,
#[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!();
// Execute interactive mode
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(())
}