Skip to content

Commit 32c127e

Browse files
committed
fix(weidu): Fixed arg weidu binary
Signed-off-by: dark0dave <[email protected]>
1 parent b6a0795 commit 32c127e

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

src/args.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct Args {
3636
short,
3737
long,
3838
value_parser = parse_absolute_path,
39+
default_value_os_t = find_weidu_bin(),
3940
default_missing_value = find_weidu_bin_on_path(),
4041
required = weidu_bin_not_on_path()
4142
)]
@@ -142,28 +143,24 @@ fn parse_absolute_path(arg: &str) -> Result<PathBuf, String> {
142143
}
143144
}
144145

145-
fn weidu_bin_not_on_path() -> bool {
146+
fn find_weidu_bin() -> PathBuf {
146147
if let Some(paths) = var_os("PATH") {
147148
for path in split_paths(&paths) {
148149
let full_path = path.join(WEIDU_FILE_NAME);
149-
if full_path.is_file() {
150-
return false;
150+
if full_path.is_file() && !full_path.is_dir() {
151+
return full_path
151152
}
152153
}
153154
}
154-
true
155+
PathBuf::new()
155156
}
156157

157158
fn find_weidu_bin_on_path() -> OsStr {
158-
if let Some(paths) = var_os("PATH") {
159-
for path in split_paths(&paths) {
160-
let full_path = path.join(WEIDU_FILE_NAME);
161-
if full_path.is_file() {
162-
return OsStr::from(full_path.into_os_string());
163-
}
164-
}
165-
}
166-
OsStr::from("")
159+
OsStr::from(find_weidu_bin().into_os_string())
160+
}
161+
162+
fn weidu_bin_not_on_path() -> bool {
163+
find_weidu_bin().is_file()
167164
}
168165

169166
#[cfg(test)]

src/main.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ fn main() -> ExitCode {
3131
\/ \/\___/ \__,_| |_|_| |_|___/\__\__,_|_|_|\___|_|
3232
"
3333
);
34-
let args = match Args::try_parse() {
35-
Ok(args) => args,
36-
Err(err) => {
37-
log::error!("Could not parse args, {}", err);
38-
return ExitCode::FAILURE;
39-
}
40-
};
34+
let args = Args::parse();
4135
let parser_config: Arc<ParserConfig> = match confy::load(CARGO_PKG_NAME, "config") {
4236
Ok(config) => Arc::new(config),
4337
Err(err) => {

0 commit comments

Comments
 (0)