use clap::{Arg, Command};
use netscape_bookmark_parser::{generate_bookmark_html, generate_json_from_html};
use std::path::Path;
fn main() {
let matches = Command::new("netspace-bookmark-parser")
.version("1.0")
.about("Converts between Chrome/Edge bookmarks JSON and HTML formats")
.arg(Arg::new("input")
.short('i')
.long("input")
.value_name("FILE")
.help("Input file path")
.required(true))
.arg(Arg::new("output")
.short('o')
.long("output")
.value_name("FILE")
.help("Output file path")
.required(true))
.arg(Arg::new("direction")
.short('d')
.long("direction")
.value_name("json2html|html2json")
.help("Conversion direction")
.required(true))
.get_matches();
let input = matches.get_one::<String>("input").unwrap();
let output = matches.get_one::<String>("output").unwrap();
let direction = matches.get_one::<String>("direction").unwrap();
match direction.as_str() {
"json2html" => {
if !Path::new(input).exists() {
eprintln!("Input file does not exist: {}", input);
std::process::exit(1);
}
if let Err(e) = generate_bookmark_html::run(input, output) {
eprintln!("Error converting JSON to HTML: {}", e);
std::process::exit(1);
}
},
"html2json" => {
if !Path::new(input).exists() {
eprintln!("Input file does not exist: {}", input);
std::process::exit(1);
}
if let Err(e) = generate_json_from_html::run(input, output) {
eprintln!("Error converting HTML to JSON: {}", e);
std::process::exit(1);
}
},
_ => {
eprintln!("Invalid direction. Use either 'json2html' or 'html2json'");
std::process::exit(1);
}
}
println!("Conversion completed successfully!");
println!("Output saved to: {}", output);
}