summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 2dda38fe978f83c6bc5b2e97b2bd328103c3542a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use crate::random_tables::RandomTables;

mod cli;
mod dice;
mod random_tables;

fn main() {
    let matches = cli::cli().get_matches();

    match matches.subcommand() {
        Some(("roll", sub_matches)) => {
            let formula = sub_matches.get_one::<String>("FORMULA").expect("required");
            match dice::roll_formula(formula) {
                Some(roll_result) => println!("Rolled: {}", roll_result),
                None => eprintln!("Error: Invalid roll formula or calculation failed.")
            }
        }
        Some(("random", sub_matches)) => {
            let random_tables = RandomTables::new().unwrap();
            let table_name = sub_matches.get_one::<String>("TABLE").expect("required");
            let output_text = random_tables.roll_table(table_name);
            println!("{}", output_text)
        }
        _ => unreachable!()
    }
}