use clap::{Parser, Subcommand};
use xml2rdf::*;
#[derive(Parser)]
#[command(version, about = "Converts XML data into RDF format.")]
struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
enum Commands {
Convert {
#[arg(short, long, default_value = "https://decisym.ai/xml2rdf/data")]
namespace: String,
#[arg(short, long, num_args = 1..)]
xml: Vec<String>,
#[arg(short, long)]
output_file: Option<String>,
},
}
fn main() {
let cli = Cli::parse();
match &cli.command {
Some(Commands::Convert {
namespace,
xml,
output_file,
}) => {
let mut w: Box<dyn writer::RdfWriter> = if let Some(file) = output_file {
match writer::FileWriter::to_file(file.clone()) {
Err(e) => {
eprintln!("Error opening file for writing: {e}");
return;
}
Ok(v) => Box::new(v),
}
} else {
Box::new(writer::FileWriter::to_stdout())
};
match convert::parse_xml(xml.clone(), w.as_mut(), namespace) {
Ok(_) => {}
Err(e) => eprintln!("Error writing: {}", e),
}
}
None => {}
}
}