From ade67863b05ed0ee11b479b908dde0d516b88286 Mon Sep 17 00:00:00 2001 From: Joeri van Ruth Date: Fri, 15 Dec 2017 10:26:57 +0200 Subject: [PATCH] Add --path flag to 'rustup doc' --- src/rustup-cli/rustup_mode.rs | 12 +++++++++++- src/rustup/toolchain.rs | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rustup-cli/rustup_mode.rs b/src/rustup-cli/rustup_mode.rs index 21524e1b5a..6d0ac0497f 100644 --- a/src/rustup-cli/rustup_mode.rs +++ b/src/rustup-cli/rustup_mode.rs @@ -293,6 +293,9 @@ 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") .help("The Rust Programming Language book")) @@ -788,7 +791,14 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> { "index.html" }; - Ok(try!(cfg.open_docs_for_dir(&try!(utils::current_dir()), doc_url))) + let cwd = try!(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(try!(cfg.open_docs_for_dir(&cwd, doc_url))) + } } fn man(cfg: &Cfg, m: &ArgMatches) -> Result<()> { diff --git a/src/rustup/toolchain.rs b/src/rustup/toolchain.rs index 38edd8d4f2..755e79e346 100644 --- a/src/rustup/toolchain.rs +++ b/src/rustup/toolchain.rs @@ -440,6 +440,7 @@ impl<'a> Toolchain<'a> { Ok(doc_dir) } + pub fn open_docs(&self, relative: &str) -> Result<()> { try!(self.verify());