diff options
-rw-r--r-- | src/cli.rs | 7 | ||||
-rw-r--r-- | src/main.rs | 13 |
2 files changed, 17 insertions, 3 deletions
@@ -9,8 +9,13 @@ pub fn cli() -> Command { .arg_required_else_help(true) .allow_external_subcommands(true) .subcommand(Command::new("roll") - .about("Rolls dice based on a given formula.") + .about("Rolls dice based on a given formula") .arg(arg!(<FORMULA> "The dice rolling formula")) .arg_required_else_help(true), ) + .subcommand(Command::new("random") + .about("Rolls on a random table") + .arg(arg!(<TABLE> "The name of the table to roll on")) + .arg_required_else_help(true), + ) } 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!() } } |