Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Deduplicate
  • Loading branch information
Byron committed Mar 6, 2023
1 parent a501d65 commit c2e0eb2
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 34 deletions.
5 changes: 0 additions & 5 deletions src/haiku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ pub fn commands<T: AsRef<OsStr>>(path: T) -> Vec<Command> {
vec![cmd]
}

pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
let cmd = &mut commands(path)[0];
cmd.status_without_output().into_result(cmd)
}

pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> {
let mut cmd = Command::new(app.into());
cmd.arg(path.as_ref())
Expand Down
5 changes: 0 additions & 5 deletions src/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ pub fn commands<T: AsRef<OsStr>>(path: T) -> Vec<Command> {
vec![cmd]
}

pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
let cmd = &mut commands(path)[0];
cmd.status_without_output().into_result(cmd)
}

pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> {
let mut cmd = Command::new("uiopen");
cmd.arg("--url")
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,16 @@ use std::{
/// Sometimes, depending on the platform and system configuration, launchers *can* block.
/// If you want to be sure they don't, use [`that_in_background()`] instead.
pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
os::that(path)
let mut last_err = None;
for mut cmd in commands(path) {
match cmd.status_without_output() {
Ok(status) => {
return Ok(status).into_result(&cmd);
}
Err(err) => last_err = Some(err),
}
}
Err(last_err.expect("no launcher worked, at least one error"))
}

/// Open path with the given application.
Expand Down
5 changes: 0 additions & 5 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ pub fn commands<T: AsRef<OsStr>>(path: T) -> Vec<Command> {
vec![cmd]
}

pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
let cmd = &mut commands(path)[0];
cmd.status_without_output().into_result(cmd)
}

pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> {
let mut cmd = Command::new("/usr/bin/open");
cmd.arg(path.as_ref())
Expand Down
13 changes: 0 additions & 13 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,6 @@ pub fn commands<T: AsRef<OsStr>>(path: T) -> Vec<Command> {
.collect()
}

pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
let mut last_err = None;
for mut cmd in commands(path) {
match cmd.status_without_output() {
Ok(status) => {
return Ok(status).into_result(&cmd);
}
Err(err) => last_err = Some(err),
}
}
Err(last_err.expect("no launcher worked, at least one error"))
}

pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> {
let mut cmd = Command::new(app.into());
cmd.arg(path.as_ref())
Expand Down
5 changes: 0 additions & 5 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ pub fn commands<T: AsRef<OsStr>>(path: T) -> Vec<Command> {
vec![cmd]
}

pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
let cmd = &mut commands(path)[0];
cmd.status_without_output().into_result(cmd)
}

pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> {
let mut cmd = Command::new("cmd");
cmd.arg("/c")
Expand Down

0 comments on commit c2e0eb2

Please sign in to comment.