From cbce9341e775d8284716e3ad6f9784786e764a07 Mon Sep 17 00:00:00 2001 From: "Christoph J. Scherr" Date: Thu, 25 Jul 2024 17:44:02 +0200 Subject: [PATCH] feat(wordlist): allow selection of wl in cli --- src/bin/bench/cli.rs | 13 ++++++++++++- src/bin/game/cli.rs | 12 +++++++++++- src/bin/solve/simple.rs | 20 ++++++++++++++++++-- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/src/bin/bench/cli.rs b/src/bin/bench/cli.rs index cda7541..434b783 100644 --- a/src/bin/bench/cli.rs +++ b/src/bin/bench/cli.rs @@ -41,6 +41,13 @@ struct Cli { /// Note that the application as the whole will use at least one more thread. #[arg(short, long, default_value_t = num_cpus::get())] threads: usize, + + /// select a wordlist + /// + /// 'ger' and 'eng' are special values bundled with this executable, if the value does not + /// match either of those, it will be assumed to be a file path. + #[arg(short, long, default_value_t = String::from("eng"))] + wordlist: String, } fn main() -> anyhow::Result<()> { @@ -52,7 +59,11 @@ fn main() -> anyhow::Result<()> { } trace!("dumping CLI: {:#?}", cli); - let wl = BuiltinWList::default(); + let wl = match cli.wordlist.as_str() { + "ger" => BuiltinWList::german(cli.length), + "eng" => BuiltinWList::english(cli.length), + _ => BuiltinWList::load(&cli.wordlist, cli.length)?, + }; let builder: GameBuilder<'_, BuiltinWList> = game::Game::builder(&wl) .length(cli.length) .max_steps(cli.max_steps) diff --git a/src/bin/game/cli.rs b/src/bin/game/cli.rs index e8bbf14..29ccdec 100644 --- a/src/bin/game/cli.rs +++ b/src/bin/game/cli.rs @@ -27,6 +27,12 @@ struct Cli { /// more verbose logs #[arg(short, long)] verbose: bool, + /// select a wordlist + /// + /// 'ger' and 'eng' are special values bundled with this executable, if the value does not + /// match either of those, it will be assumed to be a file path. + #[arg(short, long, default_value_t = String::from("eng"))] + wordlist: String, } fn main() -> anyhow::Result<()> { @@ -38,7 +44,11 @@ fn main() -> anyhow::Result<()> { } debug!("dumping CLI: {:#?}", cli); - let wl = BuiltinWList::default(); + let wl = match cli.wordlist.as_str() { + "ger" => BuiltinWList::german(cli.length), + "eng" => BuiltinWList::english(cli.length), + _ => BuiltinWList::load(&cli.wordlist, cli.length)?, + }; let builder = game::Game::builder(&wl) .length(cli.length) .max_steps(cli.max_steps) diff --git a/src/bin/solve/simple.rs b/src/bin/solve/simple.rs index 19e274a..dc6cbd4 100644 --- a/src/bin/solve/simple.rs +++ b/src/bin/solve/simple.rs @@ -50,6 +50,13 @@ struct Cli { /// behavior. #[arg(short, long)] solution: Option, + + /// select a wordlist + /// + /// 'ger' and 'eng' are special values bundled with this executable, if the value does not + /// match either of those, it will be assumed to be a file path. + #[arg(short, long, default_value_t = String::from("eng"))] + wordlist: String, } #[derive(Subcommand, Debug, EnumIter, Clone)] @@ -116,7 +123,11 @@ fn main() -> anyhow::Result<()> { } fn help_guess_interactive(cli: Cli) -> anyhow::Result<()> { - let wl = BuiltinWList::default(); + let wl = match cli.wordlist.as_str() { + "ger" => BuiltinWList::german(cli.length), + "eng" => BuiltinWList::english(cli.length), + _ => BuiltinWList::load(&cli.wordlist, cli.length)?, + }; let builder = game::GameBuilder::new(&wl, false) .length(cli.length) .max_steps(cli.max_steps) @@ -202,7 +213,12 @@ fn wlcommand_handler(_cli: &Cli, cmd: &WlCommand, wl: &impl WordList) -> anyhow: } fn play_native_non_interactive(cli: Cli) -> anyhow::Result<()> { - let wl = BuiltinWList::default(); + let wl = match cli.wordlist.as_str() { + "ger" => BuiltinWList::german(cli.length), + "eng" => BuiltinWList::english(cli.length), + _ => BuiltinWList::load(&cli.wordlist, cli.length)?, + }; + debug!("wordlist: {wl}"); let mut builder = game::Game::builder(&wl) .length(cli.length) .max_steps(cli.max_steps)