Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiple default values combined with ArgEnum / PossibleValues #3541

Merged
merged 2 commits into from Mar 7, 2022

Conversation

plaflamme
Copy link
Contributor

Fixes a regression when combining ArgEnum and a default_value with multiple values, e.g.:

#[derive(ArgEnum)]
enum Arg {
  Foo,
  Bar,
}

#[derive(Parser)]
struct Opts {
  #[clarp(arg_enum, default_value="foo,bar", value_delimiter=',')]
  arg: Vec<Arg>
}

This results in the following error and backtrace:

thread 'arg_enum::vec_type_default_value' panicked at 'Argument `arg`'s default_value=foo,bar doesn't match possible values', src/build/debug_asserts.rs:691:21
stack backtrace:
   0: rust_begin_unwind
             at /rustc/8769f4ef2fe1efddd1f072485f97f568e7328f79/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/8769f4ef2fe1efddd1f072485f97f568e7328f79/library/core/src/panicking.rs:143:14
   2: clap::build::debug_asserts::assert_defaults
             at ./src/build/debug_asserts.rs:691:21
   3: clap::build::debug_asserts::assert_arg
             at ./src/build/debug_asserts.rs:623:5
   4: clap::build::debug_asserts::assert_app
             at ./src/build/debug_asserts.rs:57:9
   5: clap::build::command::App::_build
             at ./src/build/command.rs:4101:13
   6: clap::build::command::App::_do_parse
             at ./src/build/command.rs:3965:9
   7: clap::build::command::App::try_get_matches_from_mut
             at ./src/build/command.rs:681:9
   8: clap::build::command::App::try_get_matches_from
             at ./src/build/command.rs:597:9
   9: clap::derive::Parser::try_parse_from
             at ./src/derive.rs:126:23
  10: derive::arg_enum::vec_type_default_value
             at ./tests/derive/arg_enum.rs:480:9
  11: derive::arg_enum::vec_type_default_value::{{closure}}
             at ./tests/derive/arg_enum.rs:462:1
  12: core::ops::function::FnOnce::call_once
             at /rustc/8769f4ef2fe1efddd1f072485f97f568e7328f79/library/core/src/ops/function.rs:227:5
  13: core::ops::function::FnOnce::call_once
             at /rustc/8769f4ef2fe1efddd1f072485f97f568e7328f79/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

This is essentially the same issue as #3514, but with PossibleValues instead of FromStr.

@epage
Copy link
Member

epage commented Mar 7, 2022

Thanks! I missed this case in #3521

@epage epage merged commit 8170754 into clap-rs:master Mar 7, 2022
@epage
Copy link
Member

epage commented Mar 7, 2022

v3.1.6 is now released with this fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants