Skip to content

Commit

Permalink
Merge pull request #1453 from da-x/rustup-doc-path
Browse files Browse the repository at this point in the history
Add --path flag to 'rustup doc'
  • Loading branch information
Diggsey authored Jul 7, 2018
2 parents cc1de61 + 9f1df88 commit a675b7e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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<()> {
Expand Down
17 changes: 17 additions & 0 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()));
});
}

0 comments on commit a675b7e

Please sign in to comment.