use anyhow::Result;
use clap::{Parser, Subcommand};
use haqor_core::bible::Bible;
use log::info;
use std::env;
#[derive(Parser, Debug)]
#[command(name = "haqor")]
#[command(author = "James McCorrie <djmccorrie@gmail.com>")]
#[command(version = "0.1")]
#[command(
about = "CLI for haqor",
long_about = "This tool is mostly for testing purposes. It allows basic
operations with the backend rust based engine. It's not expected to have
utility beyond that at this stage."
)]
struct Cli {
#[arg(short, long, action = clap::ArgAction::Count)]
verbose: u8,
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
enum Commands {
Get { book: u8, chapter: u8, verse: u8 },
}
fn main() -> Result<()> {
let cli = Cli::parse();
if env::var("RUST_LOG").is_err() {
unsafe {
env::set_var(
"RUST_LOG",
match cli.verbose {
0 => "Error",
1 => "Info",
2 => "Debug",
_ => "Trace",
},
)
};
}
env_logger::init();
match cli.command {
Commands::Get {
book,
chapter,
verse,
} => {
info!("Bible reference:{} {}:{}", book, chapter, verse);
let bible: Bible = Bible::default();
println!("{}", bible.get(book, chapter, verse)?)
}
}
Ok(())
}