This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
61 lines (52 loc) 路 1.56 KB
/
main.rs
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
use std::{env, fs};
use std::process::exit;
use console::style;
fn main() {
let mut output = String::new();
let mut args = env::args();
args.next(); // skip first argument (executable)
// second argument (filepath or help menu)
match args.next() {
Some(arg) => {
let is_help_needed = env::args().len() == 2
&& (arg == "-h" || arg == "--help");
if is_help_needed {
println!("{}", format!(
"{}: eco-rs bom dia! {}",
style("Example").green(),
style("// bom dia!").dim()
));
exit(0);
}
match fs::read_to_string(&arg) {
Ok(text) => {
println!("{}", text);
return
},
Err(_) => {},
}
output.push_str(&format!("{arg} "));
},
None => {
println!("");
exit(0);
}
}
while let Some(arg) = args.next() {
if arg.to_lowercase().contains("rust") {
arg.split(' ').for_each(|word| {
if word.to_lowercase().contains("rust") {
output.push_str(&format!(
"{} ",
style(word).red()
));
} else {
output.push_str(&format!("{word} "));
}
});
continue;
}
output.push_str(&format!("{arg} "));
}
println!("{}", output.trim())
}