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 32c127e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
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 32c127e

Please sign in to comment.