Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helpful message when running cargo doc --open #5024

Merged
merged 1 commit into from
Feb 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}