Skip to content

Commit

Permalink
Run latest rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Dec 13, 2017
1 parent d52cfb2 commit ec5c7ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ use std::process::{Command, ExitStatus};
use std::ffi::OsStr;

#[cfg(not(any(target_os = "windows", target_os = "macos")))]
pub fn that<T:AsRef<OsStr>+Sized>(path: T) -> io::Result<ExitStatus> {
pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
let mut last_err: io::Result<ExitStatus> = Err(io::Error::from_raw_os_error(0));
for program in &["xdg-open", "gnome-open", "kde-open"] {
match Command::new(program).arg(path.as_ref()).spawn() {
Ok(mut child) => return child.wait(),
Err(err) => {
last_err = Err(err);
continue;
},
}
}
}
last_err
}

#[cfg(target_os = "windows")]
pub fn that<T:AsRef<OsStr>+Sized>(path: T) -> io::Result<ExitStatus> {
pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
let mut cmd = Command::new("cmd");
cmd.arg("/C").arg("start").arg("");
if let Some(s) = path.as_ref().to_str() {
Expand All @@ -69,6 +69,6 @@ pub fn that<T:AsRef<OsStr>+Sized>(path: T) -> io::Result<ExitStatus> {
}

#[cfg(target_os = "macos")]
pub fn that<T:AsRef<OsStr>+Sized>(path: T) -> io::Result<ExitStatus> {
pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
try!(Command::new("open").arg(path.as_ref()).spawn()).wait()
}
22 changes: 13 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ use std::env;
use std::process;

fn main() {
let path_or_url =
match env::args().skip(1).next() {
Some(arg) => arg,
None => {
writeln!(stderr(), "usage: open <path-or-url>").ok();
process::exit(1);
}
};
let path_or_url = match env::args().skip(1).next() {
Some(arg) => arg,
None => {
writeln!(stderr(), "usage: open <path-or-url>").ok();
process::exit(1);
}
};

if let Err(err) = open::that(&path_or_url) {
writeln!(stderr(), "An error occourred when opening '{}': {}", path_or_url, err).ok();
writeln!(
stderr(),
"An error occourred when opening '{}': {}",
path_or_url,
err
).ok();
process::exit(3);
}
}

0 comments on commit ec5c7ab

Please sign in to comment.