diff options
author | David Gay <eapoems@riseup.net> | 2023-10-01 03:47:57 -0400 |
---|---|---|
committer | David Gay <eapoems@riseup.net> | 2023-10-01 03:47:57 -0400 |
commit | 1f137171bcfc12461239746a3e2e5d42cddff952 (patch) | |
tree | b637880ac729a755c569a32d80f48024ecb65d6d /src/main.rs | |
parent | 3c1c9e6f15dd834c3f0b3ccf69ce55fa1baee97c (diff) |
random command
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 13 |
1 files changed, 11 insertions, 2 deletions
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::<String>("FORMULA").expect("required")) { - Some(result) => println!("Rolled: {}", result), + 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!() } } |