Skip to content

Commit

Permalink
Merge pull request #1478 from pickfire/doc-toolchain
Browse files Browse the repository at this point in the history
Add --toolchain option to 'rustup doc'
  • Loading branch information
nrc authored Sep 13, 2018
2 parents 22b6cdb + 154412a commit c3e4ce4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/rustup-cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ pub fn cli() -> App<'static, 'static> {
.long("reference")
.help("The Rust Reference"),
)
.arg(
Arg::with_name("toolchain")
.help(TOOLCHAIN_ARG_HELP)
.long("toolchain")
.takes_value(true),
)
.group(ArgGroup::with_name("page").args(&["book", "std", "reference"])),
);

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

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

let cwd = &utils::current_dir()?;
if m.is_present("path") {
let doc_path = try!(cfg.doc_path_for_dir(cwd, doc_url));
let doc_path = toolchain.doc_path(doc_url)?;
println!("{}", doc_path.display());
Ok(())
} else {
Ok(cfg.open_docs_for_dir(cwd, doc_url)?)
Ok(toolchain.open_docs(doc_url)?)
}
}

Expand Down
10 changes: 0 additions & 10 deletions src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,6 @@ impl Cfg {
Ok(None)
}

pub fn doc_path_for_dir(&self, path: &Path, relative: &str) -> Result<PathBuf> {
let (toolchain, _) = self.toolchain_for_dir(path)?;
toolchain.doc_path(relative)
}

pub fn open_docs_for_dir(&self, path: &Path, relative: &str) -> Result<()> {
let (toolchain, _) = self.toolchain_for_dir(path)?;
toolchain.open_docs(relative)
}

pub fn set_default_host_triple(&self, host_triple: &str) -> Result<()> {
if dist::PartialTargetTriple::from_str(host_triple).is_none() {
return Err("Invalid host triple".into());
Expand Down
17 changes: 13 additions & 4 deletions tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,14 +1424,23 @@ fn file_override_with_target_info() {
fn docs_with_path() {
setup(&|config| {
expect_ok(config, &["rustup", "default", "stable"]);
expect_ok(config, &["rustup", "toolchain", "install", "nightly"]);

let mut cmd = clitools::cmd(config, "rustup", &["doc", "--path"]);
clitools::env(config, &mut cmd);

let out = cmd.output().unwrap();
let path = format!("share{0}doc{0}rust{0}html", MAIN_SEPARATOR);
assert!(String::from_utf8(out.stdout).unwrap().contains(&path));

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()));
let mut cmd = clitools::cmd(
config,
"rustup",
&["doc", "--path", "--toolchain", "nightly"],
);
clitools::env(config, &mut cmd);

let out = cmd.output().unwrap();
assert!(String::from_utf8(out.stdout).unwrap().contains("nightly"));
});
}

0 comments on commit c3e4ce4

Please sign in to comment.