Skip to content

Clippy like --allow --deny arguments #271

Answered by pacak
Boshen asked this question in Q&A
Discussion options

You must be logged in to vote

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.

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

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Boshen
Comment options

@pacak
Comment options

Answer selected by Boshen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants