implemented getters

master
Mathias Rothenhaeusler 2021-08-29 14:36:14 +02:00
parent 1fd2169a5f
commit 3d670c84f0
193 changed files with 32 additions and 12 deletions

View File

@ -7,11 +7,11 @@ pub mod csv_compare {
use clap::ArgMatches; use clap::ArgMatches;
pub struct Params { pub struct Params {
pub delimiter: String, delimiter: String,
pub source: String, source: String,
pub compared: String, compared: String,
pub column: usize, column: usize,
pub output: String, output: String,
} }
impl Params { impl Params {
@ -24,6 +24,26 @@ pub mod csv_compare {
output: matches.value_of("output").unwrap().to_string(), output: matches.value_of("output").unwrap().to_string(),
} }
} }
pub fn delimiter(&self) -> &String {
&self.delimiter
}
pub fn source(&self) -> &String {
&self.source
}
pub fn compared(&self) -> &String {
&self.compared
}
pub fn output(&self) -> &String {
&self.output
}
pub fn column(&self) -> usize {
self.column
}
} }
pub struct CsvLine { pub struct CsvLine {

View File

@ -9,8 +9,8 @@ fn main() {
let matches = App::from_yaml(yaml).get_matches(); let matches = App::from_yaml(yaml).get_matches();
let params = Params::new_from_matches(matches); let params = Params::new_from_matches(matches);
let file = File::open(&params.source).unwrap(); let file = File::open(&params.source()).unwrap();
let file2 = File::open(&params.compared).unwrap(); let file2 = File::open(&params.compared()).unwrap();
let reader = BufReader::new(file); let reader = BufReader::new(file);
let reader2 = BufReader::new(file2); let reader2 = BufReader::new(file2);
@ -23,13 +23,13 @@ fn main() {
load_vector(&mut vec2, reader2); load_vector(&mut vec2, reader2);
for i in vec1.iter() { for i in vec1.iter() {
let splitter: Vec<&str> = i.line.split(&params.delimiter).collect(); let splitter: Vec<&str> = i.line.split(params.delimiter()).collect();
let value = splitter[params.column]; let value = splitter[params.column()];
let found = !matches!( let found = !matches!(
vec2.iter().position(|r| { vec2.iter().position(|r| {
let splitter_b: Vec<&str> = r.line.split(&params.delimiter).collect(); let splitter_b: Vec<&str> = r.line.split(params.delimiter()).collect();
let search = splitter_b[params.column]; let search = splitter_b[params.column()];
search == value search == value
}), }),
None None
@ -40,7 +40,7 @@ fn main() {
} }
} }
if params.output.is_empty() == false { if params.output().is_empty() == false {
write_to_file(params, diff); write_to_file(params, diff);
} else { } else {
print_lines(diff); print_lines(diff);

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More