Skip to content

Commit

Permalink
fix(weidu): Fixed arg weidu binary
Browse files Browse the repository at this point in the history
Signed-off-by: dark0dave <[email protected]>
  • Loading branch information
dark0dave committed Jan 18, 2025
1 parent b6a0795 commit cc7e2e1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mod_installer"
version = "9.1.0"
version = "9.2.0"
edition = "2021"
authors = [ "dark0dave" ]
documentation = "https://raw.githubusercontent.com/dark0dave/mod_installer/main/README.md"
Expand Down
23 changes: 10 additions & 13 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub struct Args {
short,
long,
value_parser = parse_absolute_path,
default_value_os_t = find_weidu_bin(),
default_missing_value = find_weidu_bin_on_path(),
required = weidu_bin_not_on_path()
)]
Expand Down Expand Up @@ -142,28 +143,24 @@ fn parse_absolute_path(arg: &str) -> Result<PathBuf, String> {
}
}

fn weidu_bin_not_on_path() -> bool {
fn find_weidu_bin() -> PathBuf {
if let Some(paths) = var_os("PATH") {
for path in split_paths(&paths) {
let full_path = path.join(WEIDU_FILE_NAME);
if full_path.is_file() {
return false;
if full_path.is_file() && !full_path.is_dir() {
return full_path;
}
}
}
true
PathBuf::new()
}

fn find_weidu_bin_on_path() -> OsStr {
if let Some(paths) = var_os("PATH") {
for path in split_paths(&paths) {
let full_path = path.join(WEIDU_FILE_NAME);
if full_path.is_file() {
return OsStr::from(full_path.into_os_string());
}
}
}
OsStr::from("")
OsStr::from(find_weidu_bin().into_os_string())
}

fn weidu_bin_not_on_path() -> bool {
find_weidu_bin().is_file()
}

#[cfg(test)]
Expand Down
8 changes: 1 addition & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ fn main() -> ExitCode {
\/ \/\___/ \__,_| |_|_| |_|___/\__\__,_|_|_|\___|_|
"
);
let args = match Args::try_parse() {
Ok(args) => args,
Err(err) => {
log::error!("Could not parse args, {}", err);
return ExitCode::FAILURE;
}
};
let args = Args::parse();
let parser_config: Arc<ParserConfig> = match confy::load(CARGO_PKG_NAME, "config") {
Ok(config) => Arc::new(config),
Err(err) => {
Expand Down

0 comments on commit cc7e2e1

Please sign in to comment.