Accept output path argument and create batch subdirectory
This commit is contained in:
16
src/main.rs
16
src/main.rs
@@ -158,24 +158,19 @@ struct CustomerTemplate {
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() != 2 {
|
||||
eprintln!("Användning: {} <csv-fil>", args[0]);
|
||||
if args.len() != 3 {
|
||||
eprintln!("Användning: {} <csv-fil> <utdatakatalog>", args[0]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let input_path = Path::new(&args[1]);
|
||||
let base_output_dir = Path::new(&args[2]);
|
||||
|
||||
if !input_path.exists() {
|
||||
eprintln!("Fel: Filen hittades inte: {:?}", input_path);
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
let output_dir = input_path.parent().unwrap_or(Path::new("."));
|
||||
|
||||
if !output_dir.exists() {
|
||||
fs::create_dir_all(output_dir)?;
|
||||
}
|
||||
|
||||
let batch = read_csv_file(input_path)?;
|
||||
println!(
|
||||
"Laddade {} transaktioner från {}",
|
||||
@@ -183,6 +178,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
batch.filename
|
||||
);
|
||||
|
||||
let batch_number = batch.filename.trim_end_matches(".csv");
|
||||
let output_dir = base_output_dir.join(batch_number);
|
||||
|
||||
fs::create_dir_all(&output_dir)?;
|
||||
|
||||
let first_date = batch.transactions.first().map(|t| t.date).unwrap();
|
||||
let last_date = batch.transactions.last().map(|t| t.date).unwrap();
|
||||
let period = format!(
|
||||
|
||||
Reference in New Issue
Block a user