Skip to content

Commit c3e4ce4

Browse files
authored
Merge pull request #1478 from pickfire/doc-toolchain
Add --toolchain option to 'rustup doc'
2 parents 22b6cdb + 154412a commit c3e4ce4

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

src/rustup-cli/rustup_mode.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ pub fn cli() -> App<'static, 'static> {
389389
.long("reference")
390390
.help("The Rust Reference"),
391391
)
392+
.arg(
393+
Arg::with_name("toolchain")
394+
.help(TOOLCHAIN_ARG_HELP)
395+
.long("toolchain")
396+
.takes_value(true),
397+
)
392398
.group(ArgGroup::with_name("page").args(&["book", "std", "reference"])),
393399
);
394400

@@ -946,6 +952,7 @@ fn override_remove(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
946952
}
947953

948954
fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
955+
let toolchain = explicit_or_dir_toolchain(cfg, m)?;
949956
let doc_url = if m.is_present("book") {
950957
"book/index.html"
951958
} else if m.is_present("std") {
@@ -956,13 +963,12 @@ fn doc(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
956963
"index.html"
957964
};
958965

959-
let cwd = &utils::current_dir()?;
960966
if m.is_present("path") {
961-
let doc_path = try!(cfg.doc_path_for_dir(cwd, doc_url));
967+
let doc_path = toolchain.doc_path(doc_url)?;
962968
println!("{}", doc_path.display());
963969
Ok(())
964970
} else {
965-
Ok(cfg.open_docs_for_dir(cwd, doc_url)?)
971+
Ok(toolchain.open_docs(doc_url)?)
966972
}
967973
}
968974

src/rustup/config.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,6 @@ impl Cfg {
467467
Ok(None)
468468
}
469469

470-
pub fn doc_path_for_dir(&self, path: &Path, relative: &str) -> Result<PathBuf> {
471-
let (toolchain, _) = self.toolchain_for_dir(path)?;
472-
toolchain.doc_path(relative)
473-
}
474-
475-
pub fn open_docs_for_dir(&self, path: &Path, relative: &str) -> Result<()> {
476-
let (toolchain, _) = self.toolchain_for_dir(path)?;
477-
toolchain.open_docs(relative)
478-
}
479-
480470
pub fn set_default_host_triple(&self, host_triple: &str) -> Result<()> {
481471
if dist::PartialTargetTriple::from_str(host_triple).is_none() {
482472
return Err("Invalid host triple".into());

tests/cli-rustup.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,14 +1424,23 @@ fn file_override_with_target_info() {
14241424
fn docs_with_path() {
14251425
setup(&|config| {
14261426
expect_ok(config, &["rustup", "default", "stable"]);
1427+
expect_ok(config, &["rustup", "toolchain", "install", "nightly"]);
14271428

14281429
let mut cmd = clitools::cmd(config, "rustup", &["doc", "--path"]);
14291430
clitools::env(config, &mut cmd);
1431+
14301432
let out = cmd.output().unwrap();
1433+
let path = format!("share{0}doc{0}rust{0}html", MAIN_SEPARATOR);
1434+
assert!(String::from_utf8(out.stdout).unwrap().contains(&path));
14311435

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+
let mut cmd = clitools::cmd(
1437+
config,
1438+
"rustup",
1439+
&["doc", "--path", "--toolchain", "nightly"],
1440+
);
1441+
clitools::env(config, &mut cmd);
1442+
1443+
let out = cmd.output().unwrap();
1444+
assert!(String::from_utf8(out.stdout).unwrap().contains("nightly"));
14361445
});
14371446
}

0 commit comments

Comments
 (0)