use clap::{Parser, Subcommand};
mod commands;
#[derive(Parser)]
#[command(name = "mx20022-cli", about = "ISO 20022 message toolkit", version)]
struct Cli {
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Inspect {
file: std::path::PathBuf,
},
Validate {
file: std::path::PathBuf,
#[arg(long, value_name = "SCHEME")]
scheme: Option<String>,
},
Codegen {
file: std::path::PathBuf,
#[arg(short, long)]
output: Option<std::path::PathBuf>,
},
Translate {
file: std::path::PathBuf,
#[arg(long)]
to: String,
#[arg(short, long)]
output: Option<std::path::PathBuf>,
#[arg(long)]
msg_id: Option<String>,
#[arg(long)]
creation_time: Option<String>,
},
}
fn main() {
let cli = Cli::parse();
let result: Result<(), Box<dyn std::error::Error>> = match cli.command {
Command::Inspect { file } => {
commands::inspect::run(&file).map_err(|e| Box::new(e) as Box<dyn std::error::Error>)
}
Command::Validate { file, scheme } => commands::validate::run(&file, scheme.as_deref())
.map_err(|e| Box::new(e) as Box<dyn std::error::Error>),
Command::Codegen { file, output } => commands::codegen::run(&file, output.as_deref())
.map_err(|e| Box::new(e) as Box<dyn std::error::Error>),
Command::Translate {
file,
to,
output,
msg_id,
creation_time,
} => commands::translate::run(
&file,
&to,
output.as_deref(),
msg_id.as_deref(),
creation_time.as_deref(),
)
.map_err(|e| Box::new(e) as Box<dyn std::error::Error>),
};
if let Err(e) = result {
eprintln!("error: {e}");
std::process::exit(1);
}
}