refactor: refactor config

This commit is contained in:
graelo 2021-03-21 11:32:57 +01:00
parent 2b331c2862
commit a26a4a56d8
4 changed files with 65 additions and 96 deletions

View file

@ -1,6 +1,4 @@
use clap::Clap;
use std::fs::OpenOptions;
use std::io::prelude::*;
use std::io::{self, Read};
use copyrat::{config::basic, run, ui::Selection};
@ -25,19 +23,5 @@ fn main() {
}
let Selection { text, .. } = selection.unwrap();
// Write output to a target_path if provided, else print to original stdout.
match opt.target_path {
None => println!("{}", text),
Some(target) => {
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(target)
.expect("Unable to open the target file");
file.write_all(text.as_bytes()).unwrap();
}
}
println!("{}", text);
}