Add helpful message when running cargo doc --open in the root of the workspace, fixes...
authordebris <marek.kotewicz@gmail.com>
Thu, 8 Feb 2018 21:50:35 +0000 (22:50 +0100)
committerdebris <marek.kotewicz@gmail.com>
Thu, 8 Feb 2018 21:50:35 +0000 (22:50 +0100)
src/cargo/ops/cargo_doc.rs
tests/doc.rs

index 9527f64aefb52f6f6e7a3da91c36f81af53acbee..3a722de2f1ea412189b670a01191b13437afe8ca 100644 (file)
@@ -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 {
index 25ac13048c997b919becc6ad420d6d7ae03db6e4..1464bdc62d7fa5afc4a742c4d1e901988c0f1d95 100644 (file)
@@ -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"));
+}