From 1f137171bcfc12461239746a3e2e5d42cddff952 Mon Sep 17 00:00:00 2001 From: David Gay Date: Sun, 1 Oct 2023 03:47:57 -0400 Subject: random command --- src/main.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index c1c7cb2..2dda38f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +use crate::random_tables::RandomTables; + mod cli; mod dice; mod random_tables; @@ -7,11 +9,18 @@ fn main() { match matches.subcommand() { Some(("roll", sub_matches)) => { - match dice::roll_formula(sub_matches.get_one::("FORMULA").expect("required")) { - Some(result) => println!("Rolled: {}", result), + let formula = sub_matches.get_one::("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::("TABLE").expect("required"); + let output_text = random_tables.roll_table(table_name); + println!("{}", output_text) + } _ => unreachable!() } } -- cgit v1.2.3