Add executable path adjustments for windows

feature/lookup-installed
trivernis 2 years ago
parent 5e019de701
commit 245693be1b
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -29,10 +29,8 @@ impl MappedCommand {
}
#[tracing::instrument(skip_all, level = "debug")]
pub async fn run(self) -> CommandResult<ExitStatus> {
if !self.path.exists() {
return Err(CommandError::NotFound(self.path));
}
pub async fn run(mut self) -> CommandResult<ExitStatus> {
self.adjust_path()?;
let exit_status = Command::new(self.path)
.args(self.args)
.stdin(Stdio::inherit())
@ -44,4 +42,31 @@ impl MappedCommand {
Ok(exit_status)
}
#[cfg(not(target_os = "windows"))]
fn adjust_path(&mut self) -> CommandResult<()> {
if !self.path.exists() {
Err(CommandError::NotFound(self.path.to_owned()))
} else {
Ok(())
}
}
#[cfg(target_os = "windows")]
fn adjust_path(&mut self) -> CommandResult<()> {
if !self.path.exists() {
let extensions = ["exe", "bat", "cmd", "ps1"];
for extension in &extensions {
let joined_path = self.path.with_extension(extension);
if joined_path.exists() {
self.path = joined_path;
return Ok(());
}
}
return Err(CommandError::NotFound(self.path.to_owned()));
}
Ok(())
}
}

Loading…
Cancel
Save