-
Given clippy like allow / deny arguments https://github.com/rust-lang/rust-clippy#allowingdenying-lints cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::... I'd like to collect this into I spent an hour and couldn't figure out a way to achieve this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I appreciate you making a ticket, it is important for me to know weak points of the documentation. Let's start simple - you want to parse a single rule that can be one of allow, warn or deny. To represent that in your code you'd use use bpaf::*;
#[derive(Debug, Clone, Bpaf)]
enum RuleState {
Allow (
/// allow the rule
#[bpaf(short('a'), long("allow"), argument("RULE"))]
String,
),
Warn {
/// warn about the rule, but allow it
#[bpaf(short, long, argument("RULE"))]
warn: String,
},
Deny {
/// deny the rule
#[bpaf(short, long, argument("RULE"))]
deny: String,
},
} With that in place you can collect multiple of those rules to a vector with ...
#[derive(Debug, Clone, Bpaf)]
pub struct Options {
#[bpaf(external(rule_state), many)]
rules: Vec<RuleState>
} Now, if you want to stick to tuples you can do that too: ...
impl RuleState {
fn to_tuple(self) -> (AllowWarnDeny, String) {
...
}
}
#[derive(Debug, Clone, Bpaf)]
pub struct Options {
#[bpaf(external(rule_state), map(RuleState::to_tuple), many)]
rules: Vec<(AllowWarnDeny, String)>
} I'm assuming you have some enum ( |
Beta Was this translation helpful? Give feedback.
I appreciate you making a ticket, it is important for me to know weak points of the documentation.
Let's start simple - you want to parse a single rule that can be one of allow, warn or deny. To represent that in your code you'd use
enum
Here I used both named variants and tuple variants to show the possibilities, you'd stick to just one.