diff options
author | David Gay <eapoems@riseup.net> | 2023-10-02 00:32:23 -0400 |
---|---|---|
committer | David Gay <eapoems@riseup.net> | 2023-10-02 00:32:23 -0400 |
commit | ce7263e0fa98daafb84295e75064e6d7efd87ba2 (patch) | |
tree | d89bd23cde00db09de6952997e6788490853230d | |
parent | 0f3c03ceace46deab3097c99e82284c617cc9277 (diff) |
Set up for random things other than tables, like henchmen
-rw-r--r-- | src/cli.rs | 8 | ||||
-rw-r--r-- | src/main.rs | 12 |
2 files changed, 18 insertions, 2 deletions
@@ -8,12 +8,18 @@ pub fn cli() -> Command { .subcommand_required(true) .arg_required_else_help(true) .allow_external_subcommands(true) + .subcommand(Command::new("random") + .about("Generates a random something") + .args_conflicts_with_subcommands(true) + .subcommand(Command::new("henchman") + .about("Generates a random henchman")), + ) .subcommand(Command::new("roll") .about("Rolls dice based on a given formula") .arg(arg!(<FORMULA> "The dice rolling formula")) .arg_required_else_help(true), ) - .subcommand(Command::new("random") + .subcommand(Command::new("table") .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 2dda38f..aa6b3bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,16 @@ fn main() { let matches = cli::cli().get_matches(); match matches.subcommand() { + Some(("random", sub_matches)) => { + // TODO: Do something better than unwrap here. + let random_command = sub_matches.subcommand().unwrap(); + match random_command { + ("henchman", _) => { + println!("Generating a random henchman..."); + } + _ => unreachable!() + } + } Some(("roll", sub_matches)) => { let formula = sub_matches.get_one::<String>("FORMULA").expect("required"); match dice::roll_formula(formula) { @@ -15,7 +25,7 @@ fn main() { None => eprintln!("Error: Invalid roll formula or calculation failed.") } } - Some(("random", sub_matches)) => { + Some(("table", 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); |