diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index bd383f1158..18c9dbb54b 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -369,6 +369,11 @@ pub fn cli() -> App<'static, 'static> { .alias("docs") .about("Open the documentation for the current toolchain") .after_help(DOC_HELP) + .arg( + Arg::with_name("path") + .long("path") + .help("Only print the path to the documentation"), + ) .arg( Arg::with_name("book") .long("book") @@ -951,7 +956,14 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> { "index.html" }; - Ok(cfg.open_docs_for_dir(&utils::current_dir()?, doc_url)?) + let cwd = &utils::current_dir()?; + if m.is_present("path") { + let doc_path = try!(cfg.doc_path_for_dir(cwd, doc_url)); + println!("{}", doc_path.display()); + Ok(()) + } else { + Ok(cfg.open_docs_for_dir(cwd, doc_url)?) + } } fn man(cfg: &Cfg, m: &ArgMatches) -> Result<()> { diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index b92d6293a2..19962b9c01 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -7,6 +7,7 @@ extern crate tempdir; use std::fs; use std::env::consts::EXE_SUFFIX; +use std::path::MAIN_SEPARATOR; use std::process; use rustup_utils::raw; use rustup_mock::clitools::{self, expect_err, expect_ok, expect_ok_ex, expect_stderr_ok, @@ -1418,3 +1419,19 @@ fn file_override_with_target_info() { ); }); } + +#[test] +fn docs_with_path() { + setup(&|config| { + expect_ok(config, &["rustup", "default", "stable"]); + + let mut cmd = clitools::cmd(config, "rustup", &["doc", "--path"]); + clitools::env(config, &mut cmd); + let out = cmd.output().unwrap(); + + let stdout = String::from_utf8(out.stdout).unwrap(); + let path = format!("share{}doc{}rust{}html", + MAIN_SEPARATOR, MAIN_SEPARATOR, MAIN_SEPARATOR); + assert!(stdout.contains(path.as_str())); + }); +}