Skip to content

Commit 4870692

Browse files
committed
add constructor to EraseOptions
1 parent f0e066c commit 4870692

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

src/dbmgr/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ use crate::{
55
db::{DatabaseBackend, DatabaseClient, EraseOptions},
66
},
77
};
8-
use std::{io::stdin, process::exit};
8+
use std::{
9+
io::{Write, stdin, stdout},
10+
process::exit,
11+
};
912
use tracing::{debug, error, info};
1013

1114
#[allow(clippy::cognitive_complexity)]
@@ -46,16 +49,7 @@ pub async fn main(cmd: DatabaseCommand, config: &Config) {
4649
info!("Connected to the database");
4750
confirm_erase(&config.database.name(), &config.database.host());
4851

49-
let opts = if content_only && keep_devices {
50-
EraseOptions::ContentOnly { keep_devices: true }
51-
} else if content_only {
52-
EraseOptions::ContentOnly {
53-
keep_devices: false,
54-
}
55-
} else {
56-
EraseOptions::Everything
57-
};
58-
52+
let opts = EraseOptions::new(content_only, keep_devices);
5953
match client.erase(opts).await {
6054
Ok(()) => info!("Success!"),
6155
Err(why) => error!("Failed to erase database: {why}"),
@@ -77,6 +71,8 @@ fn confirm_erase(database_name: &str, host: &str) {
7771
println!();
7872
print!("Type '{KEY}' to confirm: ");
7973

74+
let _ = stdout().flush();
75+
8076
let mut buf = String::new();
8177
stdin().read_line(&mut buf).unwrap_or_default();
8278

src/server/db/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,13 @@ impl DatabaseBackend for DatabaseClient {
231231
}
232232
}
233233
}
234+
235+
impl EraseOptions {
236+
pub const fn new(content_only: bool, keep_devices: bool) -> Self {
237+
if content_only {
238+
Self::ContentOnly { keep_devices }
239+
} else {
240+
Self::Everything
241+
}
242+
}
243+
}

0 commit comments

Comments
 (0)