Skip to content

Commit

Permalink
feat(short): Use short paths
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 716d060 commit d10d7a2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
35 changes: 22 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Usage: mod_installer [OPTIONS] --log-file <LOG_FILE> \

Options:
-f, --log-file <LOG_FILE>
Full path to target log [env: LOG_FILE=]
Path to target log [env: LOG_FILE=]
-g, --game-directory <GAME_DIRECTORY>
Full path to game directory [env: GAME_DIRECTORY=]
Absolute Path to game directory [env: GAME_DIRECTORY=]
-w, --weidu-binary <WEIDU_BINARY>
Full Path to weidu binary [env: WEIDU_BINARY=]
Absolute Path to weidu binary [env: WEIDU_BINARY=]
-m, --mod-directories <MOD_DIRECTORIES>
Full Path to mod directories [env: MOD_DIRECTORIES=]
Path to mod directories [env: MOD_DIRECTORIES=]
-l, --language <LANGUAGE>
Game Language [default: en_US]
-d, --depth <DEPTH>
Expand Down
24 changes: 10 additions & 14 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use clap::{ArgAction, Parser};

Expand All @@ -13,24 +13,24 @@ Please provide a valid weidu logging setting, options are:
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
pub struct Args {
/// Full path to target log
/// Path to target log
#[clap(env, long, short = 'f', value_parser = path_must_exist, required = true)]
pub log_file: PathBuf,

/// Full path to game directory
/// Absolute Path to game directory
#[clap(env, short, long, value_parser = parse_absolute_path, required = true)]
pub game_directory: PathBuf,

/// Full Path to weidu binary
/// Absolute Path to weidu binary
#[clap(env, short, long, value_parser = parse_absolute_path, required = true)]
pub weidu_binary: PathBuf,

/// Full Path to mod directories
/// Path to mod directories
#[clap(
env,
short,
long,
value_parser = parse_absolute_path,
value_parser = path_must_exist,
use_value_delimiter = true,
value_delimiter = ',',
required = true
Expand Down Expand Up @@ -67,18 +67,14 @@ fn parse_weidu_log_mode(arg: &str) -> Result<String, String> {
let mut output = vec![];
while let Some(arg) = args.next() {
match arg {
"log"
if Path::new(args.clone().next().unwrap_or("").trim())
.parent()
.is_some() =>
{
"log" if path_must_exist(arg).is_ok() => {
let path = args.next().unwrap();
output.push(format!("--{arg} {path}"));
}
"autolog" => output.push(format!("--{arg}")),
"logapp" => output.push(format!("--{arg}")),
"log-extern" => output.push(format!("--{arg}")),
_ => return Err(format!("{}Provided {}", WEIDU_LOG_MODE_ERROR, arg)),
_ => return Err(format!("{}, Provided {}", WEIDU_LOG_MODE_ERROR, arg)),
};
}
Ok(output.join(" "))
Expand Down Expand Up @@ -120,11 +116,11 @@ mod tests {
),
(
"fish",
Err(format!("{}Provided {}", WEIDU_LOG_MODE_ERROR, "fish")),
Err(format!("{}, Provided {}", WEIDU_LOG_MODE_ERROR, "fish")),
),
(
"log /home fish",
Err(format!("{}Provided {}", WEIDU_LOG_MODE_ERROR, "fish")),
Err(format!("{}, Provided {}", WEIDU_LOG_MODE_ERROR, "fish")),
),
];
for (test, expected) in tests {
Expand Down
5 changes: 4 additions & 1 deletion src/weidu_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const WEIDU_FAILED_WITH_ERROR: &str = "not installed due to errors";

const WEIDU_FINISHED: &str = "successfully installed";

const EET_FINISHED: &str = "Process ended";

#[derive(Debug)]
enum ParserState {
CollectingQuestion,
Expand Down Expand Up @@ -152,7 +154,8 @@ fn detect_weidu_finished_state(weidu_output: &str) -> Option<State> {
})
} else if comparable_output.contains(WEIDU_COMPLETED_WITH_WARNINGS) {
Some(State::CompletedWithWarnings)
} else if comparable_output.contains(WEIDU_FINISHED) {
} else if comparable_output.contains(WEIDU_FINISHED) || comparable_output.contains(EET_FINISHED)
{
Some(State::Completed)
} else {
None
Expand Down

0 comments on commit d10d7a2

Please sign in to comment.