Skip to content

Commit

Permalink
Add logger to main
Browse files Browse the repository at this point in the history
  • Loading branch information
felipet committed Mar 8, 2024
1 parent 69d129d commit 4a6125c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ categories = ["finance"]
rstest = "0.18.2"
pretty_assertions = "1.*"
clap = { version = "4.5.0", features = ["derive"] }
pretty_env_logger = "0.5.0"
log = "0.4.21"
22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ use clap::Parser;
use ibex_parser::discover;
use ibex_parser::parser_ibex::IbexParser;
use std::path::Path;
extern crate pretty_env_logger;
#[macro_use]
extern crate log;

// The minium size of a text file that might contain stock data. Files with less than this size are omitted.
const MIN_BYTES_X_FILE: u64 = 560;
Expand Down Expand Up @@ -39,22 +42,28 @@ struct Args {
}

fn main() {
pretty_env_logger::init();
let args = Args::parse();
// Check whether the stock list should be filtered to show only one stock entry.
let filter: Vec<String> = if let Some(filter) = args.filter.as_deref() {
vec![String::from(filter)]
} else {
Vec::new()
};
let mut filter: Vec<String> = Vec::new();

if let Some(x) = args.filter.as_deref() {
filter.extend_from_slice(x);
}

let path = Path::new(&args.path);
// Call discover to build a list of data files that can be parsed later.
let files = discover(path, args.file_stem.as_deref(), args.file_ext.as_deref());
debug!("List of files to be parsed:");
debug!("{:?}", files);

// Instance the parser and attempt to parse all the discovered files.
let mut parser = IbexParser::new();
// Pass the wrapped target date.
parser.target_date(args.target_date.as_deref());
if let Some(x) = parser.target_date(None) {
info!("Files that contain data for day {x} will be parsed.");
}

for file in files {
let file_string = format!("{}/{}", &args.path, file.as_str());
Expand All @@ -64,6 +73,7 @@ fn main() {
if path.metadata().unwrap().len() < MIN_BYTES_X_FILE {
continue;
}
debug!("Parsing {file_string} using filters: {:?}", filter);
let data = parser.filter_file(path, &filter);

match data {
Expand All @@ -72,7 +82,7 @@ fn main() {
println!("{}", line);
}
}
None => println!("File {file} doesn't contain valid data."),
None => warn!("File {file} doesn't contain valid data."),
}
}
}

0 comments on commit 4a6125c

Please sign in to comment.