Skip to content

Commit

Permalink
Add helpful message when running cargo doc --open in the root of the …
Browse files Browse the repository at this point in the history
…workspace, fixes #4962
  • Loading branch information
debris committed Feb 8, 2018
1 parent 5bfcaa1 commit bd7ba3c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {

if options.open_result {
let name = if pkgs.len() > 1 {
bail!("Passing multiple packages and `open` is not supported")
bail!("Passing multiple packages and `open` is not supported.\n\
Please re-run this command with `-p <spec>` where `<spec>` \
is one of the following:\n {}",
pkgs.iter().map(|p| p.name()).collect::<Vec<_>>().join("\n "));
} else if pkgs.len() == 1 {
pkgs[0].name().replace("-", "_")
} else {
Expand Down
34 changes: 34 additions & 0 deletions tests/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,3 +1034,37 @@ fn doc_all_member_dependency_same_name() {
.with_stderr_contains("[..] Updating registry `[..]`")
.with_stderr_contains("[..] Documenting a v0.1.0 ([..])"));
}

#[test]
fn doc_workspace_open_help_message() {
let p = project("foo")
.file("Cargo.toml", r#"
[workspace]
members = ["foo", "bar"]
"#)
.file("foo/Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
"#)
.file("foo/src/lib.rs", "")
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.1.0"
"#)
.file("bar/src/lib.rs", "")
.build();

// The order in which bar is compiled or documented is not deterministic
assert_that(p.cargo("doc")
.arg("--all")
.arg("--open"),
execs().with_status(101)
.with_stderr_contains("[..] Documenting bar v0.1.0 ([..])")
.with_stderr_contains("[..] Documenting foo v0.1.0 ([..])")
.with_stderr_contains("error: Passing multiple packages and `open` is not supported.")
.with_stderr_contains("Please re-run this command with `-p <spec>` where `<spec>` is one of the following:")
.with_stderr_contains(" foo")
.with_stderr_contains(" bar"));
}

0 comments on commit bd7ba3c

Please sign in to comment.