Skip to content

Commit a675b7e

Browse files
authored
Merge pull request #1453 from da-x/rustup-doc-path
Add --path flag to 'rustup doc'
2 parents cc1de61 + 9f1df88 commit a675b7e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/rustup-cli/rustup_mode.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ pub fn cli() -> App<'static, 'static> {
369369
.alias("docs")
370370
.about("Open the documentation for the current toolchain")
371371
.after_help(DOC_HELP)
372+
.arg(
373+
Arg::with_name("path")
374+
.long("path")
375+
.help("Only print the path to the documentation"),
376+
)
372377
.arg(
373378
Arg::with_name("book")
374379
.long("book")
@@ -951,7 +956,14 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
951956
"index.html"
952957
};
953958

954-
Ok(cfg.open_docs_for_dir(&utils::current_dir()?, doc_url)?)
959+
let cwd = &utils::current_dir()?;
960+
if m.is_present("path") {
961+
let doc_path = try!(cfg.doc_path_for_dir(cwd, doc_url));
962+
println!("{}", doc_path.display());
963+
Ok(())
964+
} else {
965+
Ok(cfg.open_docs_for_dir(cwd, doc_url)?)
966+
}
955967
}
956968

957969
fn man(cfg: &Cfg, m: &ArgMatches) -> Result<()> {

tests/cli-rustup.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern crate tempdir;
77

88
use std::fs;
99
use std::env::consts::EXE_SUFFIX;
10+
use std::path::MAIN_SEPARATOR;
1011
use std::process;
1112
use rustup_utils::raw;
1213
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() {
14181419
);
14191420
});
14201421
}
1422+
1423+
#[test]
1424+
fn docs_with_path() {
1425+
setup(&|config| {
1426+
expect_ok(config, &["rustup", "default", "stable"]);
1427+
1428+
let mut cmd = clitools::cmd(config, "rustup", &["doc", "--path"]);
1429+
clitools::env(config, &mut cmd);
1430+
let out = cmd.output().unwrap();
1431+
1432+
let stdout = String::from_utf8(out.stdout).unwrap();
1433+
let path = format!("share{}doc{}rust{}html",
1434+
MAIN_SEPARATOR, MAIN_SEPARATOR, MAIN_SEPARATOR);
1435+
assert!(stdout.contains(path.as_str()));
1436+
});
1437+
}

0 commit comments

Comments
 (0)