Skip to content

Commit

Permalink
Use ExitCode
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-mausch committed Jul 3, 2023
1 parent 9e89715 commit abc3ad5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::fs::File;
use std::io;
use std::io::{BufReader, Cursor, Read, Seek, SeekFrom, Write};
use std::path::Path;
use std::process::ExitCode;

use clap::{Parser, ValueEnum};
use log::{debug, error, info, warn};
Expand Down Expand Up @@ -139,11 +140,12 @@ fn get_output_stream(output: &str) -> Result<Box<dyn Write>, Box<dyn Error>> {
}
}

pub fn camt052(args: Args) {
pub fn camt052(args: Args) -> ExitCode {
get_output_stream(&args.output).and_then(|mut output_stream|
process(args.files, args.format, &mut output_stream))
.map(|()| ExitCode::SUCCESS)
.unwrap_or_else(|e| {
error!("Could not parse files {:#?}", e);
std::process::exit(1)
});
ExitCode::FAILURE
})
}
4 changes: 3 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::process::ExitCode;

use clap::Parser;
use env_logger::{Builder, Env};

use haspa_camt052_to_csv::{Args, camt052};

fn main() {
fn main() -> ExitCode {
Builder::from_env(Env::default().default_filter_or("debug")).init();

let args = Args::parse();
Expand Down

0 comments on commit abc3ad5

Please sign in to comment.