Skip to content

Commit d92bd3a

Browse files
committed
Auto merge of #6505 - DamianX:print_examples, r=ehuss
--{example,bin,bench,test} with no argument now lists all available targets ``` cargo run --bin error: "--bin" takes one argument. Available binaries: cargo error: process didn't exit successfully: `target\debug\cargo.exe run --bin` (exit code: 101) ``` Previous PR: #5062 Closes #2548 Notes: - `optional_opt` is a weird name, can someone come up with a better one? - Should I call clap's `usage()` as well when printing the error message?
2 parents b84e625 + a51759c commit d92bd3a

File tree

15 files changed

+347
-19
lines changed

15 files changed

+347
-19
lines changed

src/bin/cargo/commands/bench.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ Compilation can be customized with the `bench` profile in the manifest.
7272

7373
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
7474
let ws = args.workspace(config)?;
75-
let mut compile_opts = args.compile_options(config, CompileMode::Bench)?;
75+
let mut compile_opts = args.compile_options(config, CompileMode::Bench, Some(&ws))?;
76+
7677
compile_opts.build_config.release = true;
7778

7879
let ops = TestOptions {

src/bin/cargo/commands/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ the --release flag will use the `release` profile instead.
4848

4949
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5050
let ws = args.workspace(config)?;
51-
let mut compile_opts = args.compile_options(config, CompileMode::Build)?;
51+
let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws))?;
52+
5253
compile_opts.export_dir = args.value_of_path("out-dir", config);
5354
if compile_opts.export_dir.is_some() && !config.cli_unstable().unstable_options {
5455
Err(failure::format_err!(

src/bin/cargo/commands/check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6868
}
6969
};
7070
let mode = CompileMode::Check { test };
71-
let compile_opts = args.compile_options(config, mode)?;
71+
let compile_opts = args.compile_options(config, mode, Some(&ws))?;
72+
7273
ops::compile(&ws, &compile_opts)?;
7374
Ok(())
7475
}

src/bin/cargo/commands/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5050
let mode = CompileMode::Doc {
5151
deps: !args.is_present("no-deps"),
5252
};
53-
let mut compile_opts = args.compile_options(config, mode)?;
53+
let mut compile_opts = args.compile_options(config, mode, Some(&ws))?;
5454
compile_opts.local_rustdoc_args = if args.is_present("document-private-items") {
5555
Some(vec!["--document-private-items".to_string()])
5656
} else {

src/bin/cargo/commands/fix.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
122122

123123
// Unlike other commands default `cargo fix` to all targets to fix as much
124124
// code as we can.
125-
let mut opts = args.compile_options(config, mode)?;
125+
let mut opts = args.compile_options(config, mode, Some(&ws))?;
126+
126127
if let CompileFilter::Default { .. } = opts.filter {
127128
opts.filter = CompileFilter::Only {
128129
all_targets: true,

src/bin/cargo/commands/install.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
7878
let registry = args.registry(config)?;
7979

8080
config.reload_rooted_at_cargo_home()?;
81-
let mut compile_opts = args.compile_options(config, CompileMode::Build)?;
81+
82+
let workspace = args.workspace(config).ok();
83+
let mut compile_opts = args.compile_options(config, CompileMode::Build, workspace.as_ref())?;
8284

8385
compile_opts.build_config.release = !args.is_present("debug");
8486

src/bin/cargo/commands/run.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ run. If you're passing arguments to both Cargo and the binary, the ones after
3939
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
4040
let ws = args.workspace(config)?;
4141

42-
let mut compile_opts = args.compile_options(config, CompileMode::Build)?;
42+
let mut compile_opts = args.compile_options(config, CompileMode::Build, Some(&ws))?;
43+
4344
if !args.is_present("example") && !args.is_present("bin") {
4445
let default_runs: Vec<_> = compile_opts
4546
.spec

src/bin/cargo/commands/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6262
return Err(CliError::new(err, 101));
6363
}
6464
};
65-
let mut compile_opts = args.compile_options_for_single_package(config, mode)?;
65+
let mut compile_opts = args.compile_options_for_single_package(config, mode, Some(&ws))?;
6666
let target_args = values(args, "args");
6767
compile_opts.target_rustc_args = if target_args.is_empty() {
6868
None

src/bin/cargo/commands/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ the `cargo help pkgid` command.
5151
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
5252
let ws = args.workspace(config)?;
5353
let mut compile_opts =
54-
args.compile_options_for_single_package(config, CompileMode::Doc { deps: false })?;
54+
args.compile_options_for_single_package(config, CompileMode::Doc { deps: false }, Some(&ws))?;
5555
let target_args = values(args, "args");
5656
compile_opts.target_rustdoc_args = if target_args.is_empty() {
5757
None

src/bin/cargo/commands/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ To get the list of all options available for the test binaries use this:
9292
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
9393
let ws = args.workspace(config)?;
9494

95-
let mut compile_opts = args.compile_options(config, CompileMode::Test)?;
95+
let mut compile_opts = args.compile_options(config, CompileMode::Test, Some(&ws))?;
9696

9797
let doc = args.is_present("doc");
9898
if doc {

0 commit comments

Comments
 (0)