wrote the tool!
This commit is contained in:
43
src/main.rs
Normal file
43
src/main.rs
Normal file
@@ -0,0 +1,43 @@
|
||||
use clap::Parser;
|
||||
use std::{
|
||||
fs::{File, read_to_string},
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
process::exit,
|
||||
};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(
|
||||
version,
|
||||
about,
|
||||
long_about = "This fixes files that sometimes get fucked up by Windows not using the stanard \\n notation for new lines."
|
||||
)]
|
||||
struct Args {
|
||||
#[arg(short, long, help = "the file to fix")]
|
||||
input: PathBuf,
|
||||
|
||||
#[arg(short, long, help = "the path to save the fixed file")]
|
||||
output: PathBuf,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
let file_read_res = read_to_string(args.input);
|
||||
if file_read_res.is_err() {
|
||||
println!("error reading broken file!");
|
||||
println!("{}", file_read_res.err().unwrap());
|
||||
exit(1);
|
||||
}
|
||||
let borked_string = file_read_res.unwrap();
|
||||
let file_open_res = File::create_new(args.output);
|
||||
if file_open_res.is_err() {
|
||||
println!("error opening output file!");
|
||||
println!("{}", file_open_res.err().unwrap());
|
||||
exit(1);
|
||||
}
|
||||
let mut outfile = file_open_res.unwrap();
|
||||
let fixed_lines: Vec<&str> = borked_string.split("\\n").collect();
|
||||
for line in fixed_lines {
|
||||
write!(outfile, "{}\n", line).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user