2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 1
1
use std:: ffi:: OsString ;
2
+ use std:: fmt:: Write as _;
2
3
use std:: iter;
3
4
use std:: path:: Path ;
4
5
@@ -69,10 +70,20 @@ pub fn run(
69
70
names. join( ", " )
70
71
)
71
72
} else {
72
- anyhow:: bail!(
73
- "`cargo run` can run at most one executable, but \
73
+ let mut message = "`cargo run` can run at most one executable, but \
74
74
multiple were specified"
75
- )
75
+ . to_owned ( ) ;
76
+ write ! ( & mut message, "\n help: available targets:" ) ?;
77
+ for ( pkg, bin) in & bins {
78
+ write ! (
79
+ & mut message,
80
+ "\n {} `{}` in package `{}`" ,
81
+ bin. kind( ) . description( ) ,
82
+ bin. name( ) ,
83
+ pkg. name( )
84
+ ) ?;
85
+ }
86
+ anyhow:: bail!( message)
76
87
}
77
88
}
78
89
Original file line number Diff line number Diff line change @@ -836,6 +836,11 @@ fn ambiguous_bin_name() {
836
836
. with_status ( 101 )
837
837
. with_stderr_data ( str![ [ r#"
838
838
[ERROR] `cargo run` can run at most one executable, but multiple were specified
839
+ [HELP] available targets:
840
+ bin `ambiguous` in package `crate1`
841
+ bin `ambiguous` in package `crate2`
842
+ bin `ambiguous` in package `crate3`
843
+ bin `ambiguous` in package `crate4`
839
844
840
845
"# ] ] )
841
846
. run ( ) ;
@@ -1014,6 +1019,9 @@ fn either_name_or_example() {
1014
1019
. with_status ( 101 )
1015
1020
. with_stderr_data ( str![ [ r#"
1016
1021
[ERROR] `cargo run` can run at most one executable, but multiple were specified
1022
+ [HELP] available targets:
1023
+ bin `a` in package `foo`
1024
+ example `b` in package `foo`
1017
1025
1018
1026
"# ] ] )
1019
1027
. run ( ) ;
0 commit comments