feat(wordlist): allow selection of wl in cli
cargo devel CI / cargo CI (push) Successful in 1m54s Details

This commit is contained in:
Christoph J. Scherr 2024-07-25 17:44:02 +02:00
parent e84c697a9e
commit cbce9341e7
3 changed files with 41 additions and 4 deletions

View File

@ -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)

View File

@ -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)

View File

@ -50,6 +50,13 @@ struct Cli {
/// behavior.
#[arg(short, long)]
solution: Option<Word>,
/// 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)