mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
parent
24888de79f
commit
48d0708aa6
@ -40,6 +40,7 @@ libc = "0.2"
|
|||||||
log = "0.4"
|
log = "0.4"
|
||||||
libgit2-sys = "0.7.5"
|
libgit2-sys = "0.7.5"
|
||||||
num_cpus = "1.0"
|
num_cpus = "1.0"
|
||||||
|
opener = "0.2.0"
|
||||||
rustfix = "0.4.2"
|
rustfix = "0.4.2"
|
||||||
same-file = "1"
|
same-file = "1"
|
||||||
semver = { version = "0.9.0", features = ["serde"] }
|
semver = { version = "0.9.0", features = ["serde"] }
|
||||||
|
@ -42,6 +42,7 @@ extern crate libgit2_sys;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate num_cpus;
|
extern crate num_cpus;
|
||||||
|
extern crate opener;
|
||||||
extern crate rustfix;
|
extern crate rustfix;
|
||||||
extern crate same_file;
|
extern crate same_file;
|
||||||
extern crate semver;
|
extern crate semver;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
|
||||||
|
use failure::Fail;
|
||||||
|
use opener;
|
||||||
|
|
||||||
use core::Workspace;
|
use core::Workspace;
|
||||||
use ops;
|
use ops;
|
||||||
@ -97,13 +99,10 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
|
|||||||
if fs::metadata(&path).is_ok() {
|
if fs::metadata(&path).is_ok() {
|
||||||
let mut shell = options.compile_opts.config.shell();
|
let mut shell = options.compile_opts.config.shell();
|
||||||
shell.status("Opening", path.display())?;
|
shell.status("Opening", path.display())?;
|
||||||
match open_docs(&path) {
|
if let Err(e) = opener::open(&path) {
|
||||||
Ok(m) => shell.status("Launching", m)?,
|
shell.warn(format!("Couldn't open docs: {}", e))?;
|
||||||
Err(e) => {
|
for cause in (&e as &Fail).iter_chain() {
|
||||||
shell.warn("warning: could not determine a browser to open docs with, tried:")?;
|
shell.warn(format!("Caused by:\n {}", cause))?;
|
||||||
for method in e {
|
|
||||||
shell.warn(format!("\t{}", method))?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,41 +110,3 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(any(target_os = "windows", target_os = "macos")))]
|
|
||||||
fn open_docs(path: &Path) -> Result<&'static str, Vec<&'static str>> {
|
|
||||||
use std::env;
|
|
||||||
let mut methods = Vec::new();
|
|
||||||
// trying $BROWSER
|
|
||||||
if let Ok(name) = env::var("BROWSER") {
|
|
||||||
match Command::new(name).arg(path).status() {
|
|
||||||
Ok(_) => return Ok("$BROWSER"),
|
|
||||||
Err(_) => methods.push("$BROWSER"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for m in ["xdg-open", "gnome-open", "kde-open"].iter() {
|
|
||||||
match Command::new(m).arg(path).status() {
|
|
||||||
Ok(_) => return Ok(m),
|
|
||||||
Err(_) => methods.push(m),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Err(methods)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
fn open_docs(path: &Path) -> Result<&'static str, Vec<&'static str>> {
|
|
||||||
match Command::new("cmd").arg("/C").arg(path).status() {
|
|
||||||
Ok(_) => Ok("cmd /C"),
|
|
||||||
Err(_) => Err(vec!["cmd /C"]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
fn open_docs(path: &Path) -> Result<&'static str, Vec<&'static str>> {
|
|
||||||
match Command::new("open").arg(path).status() {
|
|
||||||
Ok(_) => Ok("open"),
|
|
||||||
Err(_) => Err(vec!["open"]),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user