Skip to content
Discussion options

You must be logged in to vote

clap doesn't have a built-in "all" keyword for value enums, and you can't fake it with a value_parser either. A parser only ever turns one token into one value, so there's no way for all to fan out into three. You have to expand it yourself after parsing.

The clean way is to add All as a variant and let ValueEnum::value_variants() give you the rest:

use clap::{Parser, ValueEnum};

#[derive(ValueEnum, Clone, Copy, PartialEq)]
enum Output { All, X, Y, Z }

#[derive(Parser)]
struct Args {
    #[arg(long, value_delimiter = ',', default_value = "x")]
    outputs: Vec<Output>,
}

impl Args {
    fn outputs(&self) -> Vec<Output> {
        if self.outputs.contains(&Output::All) {
            Output

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by T-256
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