Skip to content

Commit 80ea3e7

Browse files
committed
fix(assert): Clean up num_args/action assert
1 parent 2bc0f45 commit 80ea3e7

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

clap_builder/src/builder/debug_asserts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,10 @@ fn assert_arg(arg: &Arg) {
693693
if arg.is_takes_value_set() {
694694
assert!(
695695
arg.get_action().takes_values(),
696-
"Argument `{}`'s selected action {:?} contradicts `takes_value`",
696+
"Argument `{}`'s action {:?} is incompatible with `num_args({:?})`",
697697
arg.get_id(),
698-
arg.get_action()
698+
arg.get_action(),
699+
arg.get_num_args().unwrap_or(1.into())
699700
);
700701
}
701702
if let Some(action_type_id) = arg.get_action().value_type_id() {

tests/builder/action.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fn set_true_with_required_if_eq() {
220220
}
221221

222222
#[test]
223-
#[should_panic = "Argument `mammal`'s selected action SetTrue contradicts `takes_value`"]
223+
#[should_panic = "Argument `mammal`'s action SetTrue is incompatible with `num_args(1..)`"]
224224
fn set_true_with_incompatible_num_args() {
225225
Command::new("test")
226226
.arg(
@@ -347,7 +347,7 @@ fn set_false_with_default_value_if_value() {
347347
}
348348

349349
#[test]
350-
#[should_panic = "Argument `mammal`'s selected action SetFalse contradicts `takes_value`"]
350+
#[should_panic = "Argument `mammal`'s action SetFalse is incompatible with `num_args(1..)`"]
351351
fn set_false_with_incompatible_num_args() {
352352
Command::new("test")
353353
.arg(
@@ -470,7 +470,7 @@ fn count_with_default_value_if_value() {
470470
}
471471

472472
#[test]
473-
#[should_panic = "Argument `mammal`'s selected action Count contradicts `takes_value`"]
473+
#[should_panic = "Argument `mammal`'s action Count is incompatible with `num_args(1..)`"]
474474
fn count_with_incompatible_num_args() {
475475
Command::new("test")
476476
.arg(
@@ -483,7 +483,7 @@ fn count_with_incompatible_num_args() {
483483
}
484484

485485
#[test]
486-
#[should_panic = "Argument `mammal`'s selected action Help contradicts `takes_value`"]
486+
#[should_panic = "Argument `mammal`'s action Help is incompatible with `num_args(1..)`"]
487487
fn help_with_incompatible_num_args() {
488488
Command::new("test")
489489
.arg(
@@ -496,7 +496,7 @@ fn help_with_incompatible_num_args() {
496496
}
497497

498498
#[test]
499-
#[should_panic = "Argument `mammal`'s selected action HelpShort contradicts `takes_value`"]
499+
#[should_panic = "Argument `mammal`'s action HelpShort is incompatible with `num_args(1..)`"]
500500
fn help_short_with_incompatible_num_args() {
501501
Command::new("test")
502502
.arg(
@@ -509,7 +509,7 @@ fn help_short_with_incompatible_num_args() {
509509
}
510510

511511
#[test]
512-
#[should_panic = "Argument `mammal`'s selected action HelpLong contradicts `takes_value`"]
512+
#[should_panic = "Argument `mammal`'s action HelpLong is incompatible with `num_args(1..)`"]
513513
fn help_long_with_incompatible_num_args() {
514514
Command::new("test")
515515
.arg(
@@ -522,7 +522,7 @@ fn help_long_with_incompatible_num_args() {
522522
}
523523

524524
#[test]
525-
#[should_panic = "Argument `mammal`'s selected action Version contradicts `takes_value`"]
525+
#[should_panic = "Argument `mammal`'s action Version is incompatible with `num_args(1..)`"]
526526
fn version_with_incompatible_num_args() {
527527
Command::new("test")
528528
.version("1.0.0")

0 commit comments

Comments
 (0)