Skip to content

Commit

Permalink
feat(open): added 'open' program
Browse files Browse the repository at this point in the history
Which uses the `open` library to open any path or url.
  • Loading branch information
Byron committed Jul 8, 2015
1 parent dee0000 commit a4c3a35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ description = "Open a path or URL using the program configured on the system"
repository = "https://github.com/Byron/open-rs"
keywords = ["open", "xdg-open", "start", "launch"]
documentation = "http://byron.github.io/open-rs"

[[bin]]
test = false
name = "open"
10 changes: 2 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@ pub fn that(path: &str) -> io::Result<ExitStatus> {

#[cfg(target_os = "windows")]
pub fn that(path: &str) -> io::Result<ExitStatus> {
match Command::new("cmd").arg("/C").arg("start").arg(path).spawn() {
Ok(mut child) => child.wait(),
Err(err) => Err(err),
}
try!(Command::new("cmd").arg("/C").arg("start").arg(path).spawn()).wait()
}

#[cfg(target_os = "macos")]
pub fn that(path: &str) -> io::Result<ExitStatus> {
match Command::new("open").arg(path).spawn() {
Ok(mut child) => child.wait(),
Err(err) => Err(err),
}
try!(Command::new("open").arg(path).spawn()).wait()
}
21 changes: 21 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extern crate open;

use std::io::{stderr, Write};
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>");
process::exit(1);
}
};

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

0 comments on commit a4c3a35

Please sign in to comment.