use crate::expr::Expression;
use anyhow::Result;
use clap::Parser;
use clap_verbosity_flag::Verbosity;
use log::info;
#[derive(Debug, Parser)]
#[command(version)]
#[command(about = "A dice roll simulator for tabletop RPGs")]
pub struct Config {
#[command(flatten)]
pub verbosity: Verbosity,
dice: Vec<String>,
}
#[derive(Debug)]
pub struct Runner {
config: Config,
}
impl Runner {
pub fn new(config: Config) -> Self {
Self { config }
}
pub fn run(&self) -> Result<()> {
let expr = self.config.dice.join(" ");
let expr = Expression::parse(expr)?;
let result = expr.roll();
info!("evaluating {expr}");
println!("{result}");
Ok(())
}
}