-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [raphael-cli] Add search + solve subcommands Move to a git-style subcommand interface and add basic support for item searching. raphael-cli solve --item-id XYZ ... raphael-cli search Archeo * [raphael-cli] Support OFS output in CLI * [raphael-cli] Do not print number of found matches * [raphael-cli] Move commands to their own files * [raphael-cli] Move arg structs to command files * Add food & potion selection to cli * Add combined stats argument to cli * Add initial-/target-quality arguments and HQ ingredient selection to cli * Add argument for custom output format to cli * Fix output specified using output-format not being valid CSV data * Streamline solver argument parsing * Improve readablility * Use `Arg::env` instead of manual implementation * Add language option to search * Add ability to search for item by `item_id` to cli * [raphael-cli] Run rustfmt * Update README to include more info about CLI * Make CLI documentation clearer on possible arguments * Trim spaces and CL char for search in cli --------- Co-authored-by: Jesse Farmer <[email protected]>
- Loading branch information
1 parent
dc6f538
commit e3c5a5f
Showing
6 changed files
with
444 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod search; | ||
pub mod solve; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use clap::{Args, ValueEnum}; | ||
use game_data::{get_item_name, Locale, RECIPES}; | ||
|
||
#[derive(Args, Debug)] | ||
pub struct SearchArgs { | ||
/// Search pattern, <PATTERN> can be a string or an item ID | ||
pub pattern: String, | ||
|
||
/// The delimiter the output uses between fields | ||
#[arg(long, alias = "OFS", default_value = " ", env = "OFS")] | ||
output_field_separator: String, | ||
|
||
/// The language the input pattern and output use | ||
#[arg(short, long, alias = "locale", value_enum, ignore_case = true, default_value_t = SearchLanguage::EN)] | ||
language: SearchLanguage, | ||
} | ||
|
||
#[derive(Copy, Clone, ValueEnum, Debug)] | ||
pub enum SearchLanguage { | ||
EN, | ||
DE, | ||
FR, | ||
JP, | ||
} | ||
|
||
impl Into<Locale> for SearchLanguage { | ||
fn into(self) -> Locale { | ||
match self { | ||
SearchLanguage::EN => Locale::EN, | ||
SearchLanguage::DE => Locale::DE, | ||
SearchLanguage::FR => Locale::FR, | ||
SearchLanguage::JP => Locale::JP, | ||
} | ||
} | ||
} | ||
|
||
pub fn execute(args: &SearchArgs) { | ||
let locale = args.language.into(); | ||
let matches: Vec<usize>; | ||
if let Ok(item_id) = u32::from_str_radix(&args.pattern, 10) { | ||
match &RECIPES | ||
.iter() | ||
.enumerate() | ||
.find(|(_, recipe)| recipe.item_id == item_id) | ||
{ | ||
Some((index, _)) => matches = Vec::from([*index]), | ||
None => matches = Vec::new(), | ||
} | ||
} else { | ||
matches = game_data::find_recipes(&args.pattern, locale); | ||
} | ||
if matches.is_empty() { | ||
println!("No matches found"); | ||
return; | ||
} | ||
|
||
for recipe_idx in matches { | ||
let recipe = &RECIPES[recipe_idx]; | ||
let name = get_item_name(recipe.item_id, false, locale); | ||
println!( | ||
"{item_id}{separator}{name}", | ||
item_id = recipe.item_id, | ||
separator = args.output_field_separator, | ||
name = name.trim_end_matches(&[' ', game_data::CL_ICON_CHAR]) | ||
); | ||
} | ||
} |
Oops, something went wrong.