Skip to content

Commit bd9237e

Browse files
committed
style: apply cargo fmt to all source files
1 parent 46e4102 commit bd9237e

24 files changed

Lines changed: 325 additions & 223 deletions

src/cli/commands/alias.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
//! Alias command implementation - manage connection aliases
22
3+
use crate::cli::utils::fuzzy_select_connection;
34
use crate::config::AppConfig;
45
use crate::database::Database;
5-
use crate::cli::utils::fuzzy_select_connection;
66
use crate::services::SshService;
77
use anyhow::{bail, Result};
88

99
/// Execute the alias command
10-
pub async fn execute(
11-
action: AliasAction,
12-
config: AppConfig,
13-
) -> Result<()> {
10+
pub async fn execute(action: AliasAction, config: AppConfig) -> Result<()> {
1411
let db = Database::new(&config)?;
1512

1613
match action {
@@ -92,7 +89,9 @@ async fn list_aliases(db: &Database, target: Option<&str>, config: &AppConfig) -
9289
let connection = if let Some(conn) = db.get_connection(target_name)? {
9390
conn
9491
} else {
95-
match fuzzy_select_connection(&ssh_service, target_name, "show aliases for", true).await? {
92+
match fuzzy_select_connection(&ssh_service, target_name, "show aliases for", true)
93+
.await?
94+
{
9695
Some(conn) => conn,
9796
None => {
9897
bail!("No connection found matching '{}'", target_name);
@@ -104,7 +103,10 @@ async fn list_aliases(db: &Database, target: Option<&str>, config: &AppConfig) -
104103

105104
if aliases.is_empty() {
106105
println!("📝 No aliases for connection '{}'", connection.name);
107-
println!(" Use 'bssh alias add <alias> {}' to create one", connection.name);
106+
println!(
107+
" Use 'bssh alias add <alias> {}' to create one",
108+
connection.name
109+
);
108110
} else {
109111
println!("📝 Aliases for '{}':", connection.name);
110112
for alias in &aliases {

src/cli/commands/backup.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use tracing::info;
66

77
pub async fn execute(output: Option<String>, config: AppConfig) -> Result<()> {
88
let db_path = &config.database_path;
9-
9+
1010
if !db_path.exists() {
1111
anyhow::bail!("Database file does not exist at {:?}", db_path);
1212
}
@@ -17,16 +17,22 @@ pub async fn execute(output: Option<String>, config: AppConfig) -> Result<()> {
1717
let parent = db_path.parent().unwrap_or_else(|| std::path::Path::new(""));
1818
let backups_dir = parent.join("backups");
1919
fs::create_dir_all(&backups_dir).context("Failed to create backups directory")?;
20-
20+
2121
let timestamp = chrono::Local::now().format("%Y-%m-%d-%H%M%S");
2222
backups_dir.join(format!("backup-{}.db", timestamp))
2323
};
2424

25-
info!("Backing up database from {:?} to {:?}", db_path, backup_path);
26-
25+
info!(
26+
"Backing up database from {:?} to {:?}",
27+
db_path, backup_path
28+
);
29+
2730
fs::copy(db_path, &backup_path).context("Failed to copy database file")?;
28-
29-
println!("✅ Database successfully backed up to: {}", backup_path.display());
30-
31+
32+
println!(
33+
"✅ Database successfully backed up to: {}",
34+
backup_path.display()
35+
);
36+
3137
Ok(())
3238
}

src/cli/commands/close.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Close command implementation - manage active sessions
22
3+
use crate::cli::utils::confirm;
34
use crate::config::AppConfig;
45
use crate::database::Database;
5-
use crate::cli::utils::confirm;
66
use anyhow::Result;
77
use nix::sys::signal::{kill, Signal};
88
use nix::unistd::Pid;
@@ -43,17 +43,26 @@ fn list_active_sessions(db: &Database) -> Result<()> {
4343
}
4444

4545
println!("📋 Active Sessions\n");
46-
println!("{:<20} {:<10} {:<25} DURATION", "CONNECTION", "PID", "STARTED");
46+
println!(
47+
"{:<20} {:<10} {:<25} DURATION",
48+
"CONNECTION", "PID", "STARTED"
49+
);
4750
println!("{}", "─".repeat(70));
4851

4952
for (conn_name, pid, started_at) in &sessions {
5053
let duration = chrono::Utc::now().signed_duration_since(*started_at);
5154
let duration_str = format_duration(duration);
52-
let pid_str = pid.map(|p| p.to_string()).unwrap_or_else(|| "-".to_string());
53-
55+
let pid_str = pid
56+
.map(|p| p.to_string())
57+
.unwrap_or_else(|| "-".to_string());
58+
5459
// Check if process is actually running
5560
let status = if let Some(p) = pid {
56-
if is_process_running(*p) { "🟢" } else { "⚠️ stale" }
61+
if is_process_running(*p) {
62+
"🟢"
63+
} else {
64+
"⚠️ stale"
65+
}
5766
} else {
5867
"❓"
5968
};
@@ -86,7 +95,12 @@ fn close_session(db: &Database, target: &str, force: bool) -> Result<()> {
8695
for (session_id, conn_name, pid, _) in sessions {
8796
if let Some(p) = pid {
8897
if is_process_running(p) {
89-
if !force && !confirm(&format!("Close session for '{}' (PID {})?", conn_name, p), true)? {
98+
if !force
99+
&& !confirm(
100+
&format!("Close session for '{}' (PID {})?", conn_name, p),
101+
true,
102+
)?
103+
{
90104
println!("Skipped.");
91105
continue;
92106
}
@@ -102,7 +116,10 @@ fn close_session(db: &Database, target: &str, force: bool) -> Result<()> {
102116
}
103117
} else {
104118
// Process not running, just update the record
105-
println!("⚠️ Session '{}' (PID {}) is stale, cleaning up...", conn_name, p);
119+
println!(
120+
"⚠️ Session '{}' (PID {}) is stale, cleaning up...",
121+
conn_name, p
122+
);
106123
db.mark_session_terminated(&session_id, -1)?;
107124
}
108125
} else {
@@ -123,7 +140,12 @@ fn close_all_sessions(db: &Database, force: bool) -> Result<()> {
123140
return Ok(());
124141
}
125142

126-
if !force && !confirm(&format!("Close all {} active sessions?", sessions.len()), false)? {
143+
if !force
144+
&& !confirm(
145+
&format!("Close all {} active sessions?", sessions.len()),
146+
false,
147+
)?
148+
{
127149
println!("Cancelled.");
128150
return Ok(());
129151
}
@@ -146,7 +168,10 @@ fn close_all_sessions(db: &Database, force: bool) -> Result<()> {
146168
// Mark all as terminated in DB
147169
db.mark_all_sessions_terminated()?;
148170

149-
println!("✅ Closed {} sessions, cleaned {} stale records", closed, cleaned);
171+
println!(
172+
"✅ Closed {} sessions, cleaned {} stale records",
173+
closed, cleaned
174+
);
150175

151176
Ok(())
152177
}

src/cli/commands/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub async fn execute(
1616
) -> Result<()> {
1717
info!("Updating application configuration");
1818

19-
// Handle bastion settings:
19+
// Handle bastion settings:
2020
// - If --clear-bastion is passed, set to Some(None) to clear
2121
// - If a value is provided, set to Some(Some(value))
2222
// - Otherwise, set to None (don't change)

src/cli/commands/duplicate.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ pub async fn execute(source: String, new_name: String, config: AppConfig) -> Res
88
let ssh_service = SshService::new(config)?;
99

1010
// Try to find the exact connection by name or alias first
11-
let mut target_conn = ssh_service.get_connection(&source).await.unwrap_or_default();
11+
let mut target_conn = ssh_service
12+
.get_connection(&source)
13+
.await
14+
.unwrap_or_default();
1215

1316
// Fall back to fuzzy search if not found
1417
if target_conn.is_none() {
@@ -25,26 +28,36 @@ pub async fn execute(source: String, new_name: String, config: AppConfig) -> Res
2528
};
2629

2730
// Check if new name already exists
28-
if ssh_service.get_connection(&new_name).await.unwrap_or_default().is_some() {
31+
if ssh_service
32+
.get_connection(&new_name)
33+
.await
34+
.unwrap_or_default()
35+
.is_some()
36+
{
2937
anyhow::bail!("A connection with the name '{}' already exists", new_name);
3038
}
3139

3240
info!("Duplicating connection {} to {}", original.name, new_name);
33-
34-
ssh_service.add_connection(
35-
new_name.clone(),
36-
original.host.clone(),
37-
Some(original.user.clone()),
38-
Some(original.port),
39-
Some(original.use_kerberos),
40-
original.bastion.clone(),
41-
original.bastion.is_none(),
42-
original.bastion_user.clone(),
43-
original.key_path.clone(),
44-
original.tags.clone(),
45-
).await?;
46-
47-
println!("✅ Successfully duplicated '{}' to '{}'", original.name, new_name);
48-
41+
42+
ssh_service
43+
.add_connection(
44+
new_name.clone(),
45+
original.host.clone(),
46+
Some(original.user.clone()),
47+
Some(original.port),
48+
Some(original.use_kerberos),
49+
original.bastion.clone(),
50+
original.bastion.is_none(),
51+
original.bastion_user.clone(),
52+
original.key_path.clone(),
53+
original.tags.clone(),
54+
)
55+
.await?;
56+
57+
println!(
58+
"✅ Successfully duplicated '{}' to '{}'",
59+
original.name, new_name
60+
);
61+
4962
Ok(())
5063
}

src/cli/commands/env.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ fn list_environments() -> Result<()> {
5858
fn use_environment(name: &str) -> Result<()> {
5959
let env_dir = get_environments_dir().join(name);
6060
if !env_dir.exists() {
61-
anyhow::bail!("Environment '{}' does not exist. Use `bayesian-ssh env create {}` to create it.", name, name);
61+
anyhow::bail!(
62+
"Environment '{}' does not exist. Use `bayesian-ssh env create {}` to create it.",
63+
name,
64+
name
65+
);
6266
}
6367

6468
AppConfig::set_active_env(name)?;
@@ -73,7 +77,7 @@ fn create_environment(name: &str) -> Result<()> {
7377
}
7478

7579
std::fs::create_dir_all(&env_dir)?;
76-
80+
7781
// Create default config for this environment
7882
let config = AppConfig::default_for_env(name);
7983
config.save()?;
@@ -86,7 +90,10 @@ fn create_environment(name: &str) -> Result<()> {
8690
fn remove_environment(name: &str) -> Result<()> {
8791
let active_env = AppConfig::get_active_env();
8892
if name == active_env {
89-
anyhow::bail!("Cannot remove the currently active environment '{}'. Change environment first.", name);
93+
anyhow::bail!(
94+
"Cannot remove the currently active environment '{}'. Change environment first.",
95+
name
96+
);
9097
}
9198

9299
if name == "default" {
@@ -99,7 +106,7 @@ fn remove_environment(name: &str) -> Result<()> {
99106
}
100107

101108
std::fs::remove_dir_all(&env_dir).context("Failed to securely delete environment directory")?;
102-
109+
103110
println!("🗑️ Removed environment '{}'", name);
104111
info!("Removed environment {}", name);
105112
Ok(())

src/cli/commands/export.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,34 @@ pub async fn execute(
4545

4646
let exported_content = match format {
4747
ExportFormat::Json => serde_json::to_string_pretty(&connections)?,
48-
ExportFormat::Toml => toml::to_string_pretty(&ConnectionsWrapper { connections: connections.clone() })?,
48+
ExportFormat::Toml => toml::to_string_pretty(&ConnectionsWrapper {
49+
connections: connections.clone(),
50+
})?,
4951
ExportFormat::SshConfig => generate_ssh_config(&connections),
5052
};
5153

5254
if let Some(output_path) = output {
5355
let expanded_path = expand_tilde(&output_path);
5456
let path = std::path::Path::new(&expanded_path);
55-
57+
5658
if let Some(parent) = path.parent() {
5759
if !parent.exists() {
5860
std::fs::create_dir_all(parent).context("Failed to create parent directories")?;
5961
}
6062
}
61-
63+
6264
let mut file = File::create(&expanded_path).context("Failed to create output file")?;
6365
file.write_all(exported_content.as_bytes())?;
64-
info!("Exported {} connections to {}", connections.len(), expanded_path);
65-
println!("✅ Exported {} connections to {}", connections.len(), expanded_path);
66+
info!(
67+
"Exported {} connections to {}",
68+
connections.len(),
69+
expanded_path
70+
);
71+
println!(
72+
"✅ Exported {} connections to {}",
73+
connections.len(),
74+
expanded_path
75+
);
6676
} else {
6777
println!("{}", exported_content);
6878
}
@@ -84,21 +94,24 @@ fn generate_ssh_config(connections: &[Connection]) -> String {
8494
config.push_str(&format!(" HostName {}\n", conn.host));
8595
config.push_str(&format!(" User {}\n", conn.user));
8696
config.push_str(&format!(" Port {}\n", conn.port));
87-
97+
8898
if let Some(key) = &conn.key_path {
8999
config.push_str(&format!(" IdentityFile {}\n", key));
90100
}
91101

92102
if let Some(bastion) = &conn.bastion {
93103
let bastion_user = conn.bastion_user.as_deref().unwrap_or(&conn.user);
94-
config.push_str(&format!(" ProxyCommand ssh -W %h:%p {}@{}\n", bastion_user, bastion));
104+
config.push_str(&format!(
105+
" ProxyCommand ssh -W %h:%p {}@{}\n",
106+
bastion_user, bastion
107+
));
95108
}
96-
109+
97110
if conn.use_kerberos {
98111
config.push_str(" GSSAPIAuthentication yes\n");
99112
config.push_str(" GSSAPIDelegateCredentials yes\n");
100113
}
101-
114+
102115
config.push('\n');
103116
}
104117

src/cli/commands/groups.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ pub async fn execute(group_name: Option<String>, config: AppConfig) -> Result<()
99

1010
if let Some(tag) = group_name {
1111
// List connections in the specific group
12-
let filtered: Vec<_> = connections.into_iter().filter(|c| c.tags.contains(&tag)).collect();
13-
12+
let filtered: Vec<_> = connections
13+
.into_iter()
14+
.filter(|c| c.tags.contains(&tag))
15+
.collect();
16+
1417
if filtered.is_empty() {
1518
println!("No connections found in group '{}'", tag);
1619
} else {
@@ -22,7 +25,7 @@ pub async fn execute(group_name: Option<String>, config: AppConfig) -> Result<()
2225
} else {
2326
// List all groups and their connection counts
2427
let mut group_counts: HashMap<String, usize> = HashMap::new();
25-
28+
2629
for conn in connections {
2730
for tag in conn.tags {
2831
*group_counts.entry(tag).or_insert(0) += 1;
@@ -35,9 +38,13 @@ pub async fn execute(group_name: Option<String>, config: AppConfig) -> Result<()
3538
println!("Available groups:");
3639
let mut groups: Vec<_> = group_counts.into_iter().collect();
3740
groups.sort_by(|a, b| a.0.cmp(&b.0)); // Sort alphabetically
38-
41+
3942
for (tag, count) in groups {
40-
let suffix = if count == 1 { "connection" } else { "connections" };
43+
let suffix = if count == 1 {
44+
"connection"
45+
} else {
46+
"connections"
47+
};
4148
println!(" - {} ({} {})", tag, count, suffix);
4249
}
4350
println!("\nUse `bssh groups <name>` to see connections in a group.");

0 commit comments

Comments
 (0)