Debian Codegraph @

src/main.rs

raw symbols SCIP
1 extern crate sanitize_filename;
2
3 fn main() -> Result<(), ::std::io::Error> {
4
5 let mut input = None;
6 let mut set_replacement = false;
7 let mut replacement = None;
8 let mut truncate = None;
9 let mut windows = None;
10
11 for arg in ::std::env::args().skip(1) {
12 if set_replacement {
13 replacement = Some(arg);
14 set_replacement = false;
15 } else if arg == "-r" || arg == "--replace" {
16 set_replacement = true;
17 } else if arg == "--truncate" {
18 truncate = Some(true);
19 } else if arg == "--no-truncate" {
20 truncate = Some(false);
21 } else if arg == "--windows" {
22 windows = Some(true);
23 } else if arg == "--no-windows" {
24 windows = Some(false);
25 } else if arg == "-" {
26 input = None;
27 } else {
28 input = Some(arg);
29 }
30 }
31
32 let input = if let Some(input) = input {
33 input
34 } else {
35 let mut buffer = String::new();
36 ::std::io::Read::read_to_string(&mut ::std::io::stdin(), &mut buffer)?;
37 buffer
38 };
39
40 let mut options = sanitize_filename::Options::default();
41
42 if let Some(ref replacement) = replacement {
43 options.replacement = replacement;
44 }
45
46 if let Some(windows) = windows {
47 options.windows = windows;
48 }
49
50 if let Some(truncate) = truncate {
51 options.truncate = truncate;
52 }
53
54 let output = sanitize_filename::sanitize_with_options(input, options);
55
56 println!("{}", &output);
57
58 Ok(())
59
60 }