diff --git a/src/main.rs b/src/main.rs index b3d41c5..98843e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,20 +2,20 @@ use std::env; use std::fs; enum Mode { - Info, - Add, - Remove, + Info, + Add, + Remove, } fn main() { let mut mode = Mode::Info; for arg in env::args().skip(1) { - match arg.as_str() { - "--add" => { mode = Mode::Add; } - "--remove" => { mode = Mode::Remove; } - _ => { process_file(&arg, &mode); } - } + match arg.as_str() { + "--add" => { mode = Mode::Add; } + "--remove" => { mode = Mode::Remove; } + _ => { process_file(&arg, &mode); } + } } } @@ -23,27 +23,27 @@ fn process_file(path: &str, mode: &Mode) { let mut content = fs::read_to_string(path).expect("could not read file"); if ends_with_newline(&content) { - match mode { - Mode::Remove => { - content.pop(); - fs::write(path, content).expect("could not write file"); - println!("\x1B[1m{}\x1B[0m: \x1B[31mno final newline [removed]\x1B[0m", path); - } - _ => { - println!("\x1B[1m{}\x1B[0m: \x1B[32mfinal newline\x1B[0m", path); - } - } + match mode { + Mode::Remove => { + content.pop(); + fs::write(path, content).expect("could not write file"); + println!("\x1B[1m{}\x1B[0m: \x1B[31mno final newline [removed]\x1B[0m", path); + } + _ => { + println!("\x1B[1m{}\x1B[0m: \x1B[32mfinal newline\x1B[0m", path); + } + } } else { - match mode { - Mode::Add => { - content.push('\n'); - fs::write(path, content).expect("could not write file"); - println!("\x1B[1m{}\x1B[0m: \x1B[32mfinal newline [added]\x1B[0m", path); - } - _ => { - println!("\x1B[1m{}\x1B[0m: \x1B[31mno final newline\x1B[0m", path); - } - } + match mode { + Mode::Add => { + content.push('\n'); + fs::write(path, content).expect("could not write file"); + println!("\x1B[1m{}\x1B[0m: \x1B[32mfinal newline [added]\x1B[0m", path); + } + _ => { + println!("\x1B[1m{}\x1B[0m: \x1B[31mno final newline\x1B[0m", path); + } + } } }