Skip to content

Commit

Permalink
fix(parse): Better parsing plus better defaults
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <dark0dave@mykolab.com>
  • Loading branch information
dark0dave committed Aug 14, 2024
1 parent 4c78d42 commit 8d806c7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ Options:
-l, --language <LANGUAGE>
Game Language [default: en_US]
-d, --depth <DEPTH>
Depth to walk folder structure [env: DEPTH=] [default: 3]
Depth to walk folder structure [env: DEPTH=] [default: 5]
-s, --skip-installed
Compare against installed weidu log, note this is best effort [env: SKIP_INSTALLED=]
Compare against installed weidu log, note this is best effort [env: SKIP_INSTALLED=] [default: true]
-a, --abort-on-warnings
If a warning occurs in the weidu child process exit [env: ABORT_ON_WARNINGS=]
If a warning occurs in the weidu child process exit, note this is best effort [env: ABORT_ON_WARNINGS=] [default: true]
-t, --timeout <TIMEOUT>
Timeout time per mod in seconds, default is 1 hour [env: TIMEOUT=] [default: 3600]
-u, --weidu-log-mode <WEIDU_LOG_MODE>
Expand Down
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct Args {
pub language: String,

/// Depth to walk folder structure
#[clap(env, long, short, default_value = "3")]
#[clap(env, long, short, default_value = "5")]
pub depth: usize,

/// Compare against installed weidu log, note this is best effort
Expand Down
41 changes: 27 additions & 14 deletions src/weidu_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,9 @@ const WEIDU_USEFUL_STATUS: [&str; 9] = [
"processing",
];

const WEIDU_CHOICE: [&str; 6] = [
"choice",
"choose",
"select",
"do you want",
"would you like",
"enter",
];
const WEIDU_CHOICE_WORDS: [&str; 4] = ["choice", "choose", "select", "enter"];

const WEIDU_CHOICE_PHRASE: [&str; 2] = ["do you want", "would you like"];

const WEIDU_COMPLETED_WITH_WARNINGS: &str = "installed with warnings";

Expand Down Expand Up @@ -139,11 +134,27 @@ fn string_looks_like_question(weidu_output: &str) -> bool {
{
return false;
}
return WEIDU_CHOICE
.iter()
.map(|choice| comparable_output.contains(choice))
.reduce(|a, b| a | b)
.unwrap_or(false);

for question in WEIDU_CHOICE_PHRASE {
if comparable_output.contains(question) {
return true;
}
}

for question in WEIDU_CHOICE_WORDS {
for word in comparable_output.split_whitespace() {
if word
.chars()
.filter(|c| c.is_alphabetic())
.collect::<String>()
== question
{
return true;
}
}
}

false
}

fn detect_weidu_finished_state(weidu_output: &str) -> Option<State> {
Expand Down Expand Up @@ -186,7 +197,9 @@ mod tests {
#[test]
fn is_not_question() {
let test = "Creating epilogues. Too many epilogues... Why are there so many options here?";
assert_eq!(string_looks_like_question(test), false)
assert_eq!(string_looks_like_question(test), false);
let test = "Including file(s) spellchoices_defensive/vanilla/ENCHANTER.TPH";
assert_eq!(string_looks_like_question(test), false);
}

#[test]
Expand Down

0 comments on commit 8d806c7

Please sign in to comment.