Skip to content

Commit 7504c58

Browse files
committed
Use clap's conflict support and keep some command tests
1 parent 09a8ece commit 7504c58

File tree

4 files changed

+40
-85
lines changed

4 files changed

+40
-85
lines changed

src/bin/cargo/commands/install.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,13 @@ pub fn cli() -> Command {
8585
)
8686
.arg_features()
8787
.arg_parallel()
88-
.arg(flag(
89-
"debug",
90-
"Build in debug mode (with the 'dev' profile) instead of release mode",
91-
))
88+
.arg(
89+
flag(
90+
"debug",
91+
"Build in debug mode (with the 'dev' profile) instead of release mode",
92+
)
93+
.conflicts_with("profile"),
94+
)
9295
.arg_redundant_default_mode("release", "install", "debug")
9396
.arg_profile("Install artifacts with the specified profile")
9497
.arg_target_triple("Build for the target triple")

src/cargo/util/command_prelude.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ pub trait CommandExt: Sized {
131131
) -> Self {
132132
let msg = format!("`--{default_mode}` is the default for `cargo {command}`; instead `--{supported_mode}` is supported");
133133
let value_parser = UnknownArgumentValueParser::suggest(msg);
134-
self._arg(flag(default_mode, "").value_parser(value_parser).hide(true))
134+
self._arg(
135+
flag(default_mode, "")
136+
.conflicts_with("profile")
137+
.value_parser(value_parser)
138+
.hide(true),
139+
)
135140
}
136141

137142
fn arg_targets_all(
@@ -226,6 +231,7 @@ pub trait CommandExt: Sized {
226231
self._arg(
227232
flag("release", release)
228233
.short('r')
234+
.conflicts_with("profile")
229235
.help_heading(heading::COMPILATION_OPTIONS),
230236
)
231237
}
@@ -563,24 +569,13 @@ Run `{cmd}` to see possible targets."
563569
) -> CargoResult<InternedString> {
564570
let specified_profile = self._value_of("profile");
565571

566-
let err_message = |flag: &str| {
567-
format!(
568-
"\
569-
the `--{flag}` flag can not be specified with the `--profile` flag
570-
Please remove one of the flags."
571-
)
572-
};
573-
574572
// Check for allowed legacy names.
575573
// This is an early exit, since it allows combination with `--release`.
576574
match (specified_profile, profile_checking) {
577575
// `cargo rustc` has legacy handling of these names
578576
(Some(name @ ("dev" | "test" | "bench" | "check")), ProfileChecking::LegacyRustc)
579577
// `cargo fix` and `cargo check` has legacy handling of this profile name
580578
| (Some(name @ "test"), ProfileChecking::LegacyTestOnly) => {
581-
if self.maybe_flag("release") {
582-
bail!(err_message("release"));
583-
}
584579
return Ok(InternedString::new(name));
585580
}
586581
_ => {}
@@ -593,9 +588,7 @@ Please remove one of the flags."
593588
) {
594589
(false, false, None) => default,
595590
(true, _, None) => "release",
596-
(true, _, Some(_)) => bail!(err_message("release")),
597591
(_, true, None) => "dev",
598-
(_, true, Some(_)) => bail!(err_message("debug")),
599592
// `doc` is separate from all the other reservations because
600593
// [profile.doc] was historically allowed, but is deprecated and
601594
// has no effect. To avoid potentially breaking projects, it is a

tests/testsuite/check.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,20 +289,26 @@ fn rustc_check() {
289289

290290
// Verify compatible usage of --profile with --release, issue #7488
291291
foo.cargo("rustc --profile check --release -- --emit=metadata")
292-
.with_status(101)
292+
.with_status(1)
293293
.with_stderr(
294294
"\
295-
error: the `--release` flag can not be specified with the `--profile` flag
296-
Please remove one of the flags.",
295+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
296+
297+
Usage: cargo rustc --profile <PROFILE-NAME> [ARGS]...
298+
299+
For more information, try '--help'.",
297300
)
298301
.run();
299302

300303
foo.cargo("rustc --profile test --release -- --emit=metadata")
301-
.with_status(101)
304+
.with_status(1)
302305
.with_stderr(
303306
"\
304-
error: the `--release` flag can not be specified with the `--profile` flag
305-
Please remove one of the flags.",
307+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
308+
309+
Usage: cargo rustc --profile <PROFILE-NAME> [ARGS]...
310+
311+
For more information, try '--help'.",
306312
)
307313
.run();
308314
}

tests/testsuite/profile_custom.rs

Lines changed: 14 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -380,85 +380,38 @@ fn conflicting_usage() {
380380
.build();
381381

382382
p.cargo("build --profile=dev --release")
383-
.with_status(101)
383+
.with_status(1)
384384
.with_stderr(
385385
"\
386-
error: the `--release` flag can not be specified with the `--profile` flag
387-
Please remove one of the flags.",
388-
)
389-
.run();
386+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
390387
391-
p.cargo("install --profile=release --debug")
392-
.with_status(101)
393-
.with_stderr(
394-
"\
395-
error: the `--debug` flag can not be specified with the `--profile` flag
396-
Please remove one of the flags.",
397-
)
398-
.run();
388+
Usage: cargo build --profile <PROFILE-NAME>
399389
400-
p.cargo("rustc --profile=dev --release")
401-
.with_status(101)
402-
.with_stderr(
403-
"\
404-
error: the `--release` flag can not be specified with the `--profile` flag
405-
Please remove one of the flags.
406-
",
390+
For more information, try '--help'.",
407391
)
408392
.run();
409393

410-
p.cargo("check --profile=dev --release")
411-
.with_status(101)
394+
p.cargo("install --profile=release --debug")
395+
.with_status(1)
412396
.with_stderr(
413397
"\
414-
error: the `--release` flag can not be specified with the `--profile` flag
415-
Please remove one of the flags.",
416-
)
417-
.run();
398+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--debug'
418399
419-
p.cargo("check --profile=test --release")
420-
.with_status(101)
421-
.with_stderr(
422-
"\
423-
error: the `--release` flag can not be specified with the `--profile` flag
424-
Please remove one of the flags.",
425-
)
426-
.run();
400+
Usage: cargo install --profile <PROFILE-NAME> [CRATE[@<VER>]]...
427401
428-
// This is OK since the two are the same.
429-
p.cargo("rustc --profile=release --release")
430-
.with_status(101)
431-
.with_stderr(
432-
"\
433-
error: the `--release` flag can not be specified with the `--profile` flag
434-
Please remove one of the flags.",
402+
For more information, try '--help'.",
435403
)
436404
.run();
437405

438-
p.cargo("build --profile=release --release")
439-
.with_status(101)
406+
p.cargo("check --profile=dev --release")
407+
.with_status(1)
440408
.with_stderr(
441409
"\
442-
error: the `--release` flag can not be specified with the `--profile` flag
443-
Please remove one of the flags.",
444-
)
445-
.run();
410+
[ERROR] the argument '--profile <PROFILE-NAME>' cannot be used with '--release'
446411
447-
p.cargo("install --path . --profile=dev --debug")
448-
.with_status(101)
449-
.with_stderr(
450-
"\
451-
error: the `--debug` flag can not be specified with the `--profile` flag
452-
Please remove one of the flags.",
453-
)
454-
.run();
412+
Usage: cargo check --profile <PROFILE-NAME>
455413
456-
p.cargo("install --path . --profile=release --debug")
457-
.with_status(101)
458-
.with_stderr(
459-
"\
460-
error: the `--debug` flag can not be specified with the `--profile` flag
461-
Please remove one of the flags.",
414+
For more information, try '--help'.",
462415
)
463416
.run();
464417
}

0 commit comments

Comments
 (0)