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
#![feature(never_type)]
use datatypes::Bread;
pub mod args;
pub mod config;
pub mod datatypes;
pub mod fs_operation;
pub fn prompt(mut conf: config::Config) -> Result<Option<()>, String> {
if conf.delete {
let mut rl = rustyline::Editor::<()>::new();
let readline = rl.readline("Are you sure you want to delete crumbs? (y/n/s): ");
match readline {
Ok(s) => match s.as_str() {
"y" => {
fs_operation::handle_files(conf).for_each(|b| println!("{}", b));
Ok(None)
}
"n" => {
conf.delete = false;
fs_operation::handle_files(conf).for_each(|b| println!("{}", b));
Ok(None)
}
"s" => {
conf.delete = false;
let breads: Vec<Bread> = fs_operation::handle_files(conf).collect();
loop {
breads.iter().for_each(|b| println!("{}", b));
let ask_again =
rl.readline("Are you sure you want to delete crumbs? (y/n/s): ");
match ask_again {
Ok(ag) => match ag.as_str() {
"y" => {
breads
.into_iter()
.for_each(|b| fs_operation::clean_the_crumbs(b).unwrap());
break;
}
"n" => break,
"s" => continue,
_ => {
println!("I don't understand, please give y/n/s");
break;
}
},
Err(e) => {
return Err(format!("error in prompt readline {}", e.to_string()))
}
}
}
Ok(None)
}
_ => return Err("I don't understand, please give y/n/s".to_string()),
},
Err(e) => return Err(format!("error in prompt readline {}", e.to_string())),
}
} else {
fs_operation::handle_files(conf).for_each(|b| println!("{}", b));
Ok(None)
}
}