List available binary names
authorKornel <kornel@geekhood.net>
Sat, 28 Oct 2017 22:03:15 +0000 (23:03 +0100)
committerKornel <kornel@geekhood.net>
Tue, 31 Oct 2017 17:11:31 +0000 (17:11 +0000)
src/cargo/ops/cargo_run.rs
tests/required-features.rs
tests/run.rs

index 3a4e7f6f2d6ede731353cd09831106d46f44394b..636a626463e26cf940f3f0c4b06ded9442aba0d6 100644 (file)
@@ -25,25 +25,28 @@ pub fn run(ws: &Workspace,
         }
     };
 
-    let mut bins = pkg.manifest().targets().iter().filter(|a| {
+    let bins: Vec<_> = pkg.manifest().targets().iter().filter(|a| {
         !a.is_lib() && !a.is_custom_build() && if !options.filter.is_specific() {
             a.is_bin()
         } else {
             options.filter.matches(a)
         }
-    });
-    if bins.next().is_none() {
+    })
+    .map(|bin| bin.name())
+    .collect();
+
+    if bins.len() == 0 {
         if !options.filter.is_specific() {
             bail!("a bin target must be available for `cargo run`")
         } else {
             // this will be verified in cargo_compile
         }
     }
-    if bins.next().is_some() {
+    if bins.len() > 1 {
         if !options.filter.is_specific() {
             bail!("`cargo run` requires that a project only have one \
                    executable; use the `--bin` option to specify which one \
-                   to run")
+                   to run ({})", bins.join(", "))
         } else {
             bail!("`cargo run` can run at most one executable, but \
                    multiple were specified")
index 0f71d6d933e2201b8b4dd2feebd72fd8aa8e3782..cdcc8d494c7d9aa8061b1c02eedfc94cdacdf263 100644 (file)
@@ -996,5 +996,5 @@ fn run_default_multiple_required_features() {
     assert_that(p.cargo("run"),
                 execs().with_status(101).with_stderr("\
 error: `cargo run` requires that a project only have one executable; \
-use the `--bin` option to specify which one to run"));
+use the `--bin` option to specify which one to run (foo1, foo2)"));
 }
index 449c91cafc628048e3b25ee1b0c4388812ea7736..66e5350e435980fe8b47142f154da880b14e05b2 100644 (file)
@@ -256,7 +256,7 @@ fn too_many_bins() {
                 execs().with_status(101)
                        .with_stderr("[ERROR] `cargo run` requires that a project only \
                                      have one executable; use the `--bin` option \
-                                     to specify which one to run\n"));
+                                     to specify which one to run ([..])\n"));
 }
 
 #[test]
@@ -278,7 +278,7 @@ fn too_many_bins_implicit() {
                 execs().with_status(101)
                        .with_stderr("[ERROR] `cargo run` requires that a project only \
                                      have one executable; use the `--bin` option \
-                                     to specify which one to run\n"));
+                                     to specify which one to run ([..])\n"));
 }
 
 #[test]