Skip to content

Interaction between env and many? #168

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

You must be logged in to vote

Not directly but you can always use parse to your advantage to replicate value_delimiter - getting a single argument and splitting it.

fn parse_ports(in: String) -> Result<Vec<u16>, String> {
    ....
}

#[derive(Debug, Clone, Bpaf)]
#[bpaf(options)]
struct Opts {
    #[bpaf(argument::<String>("PORTS"), env("PORTS"), parse(parse_ports))]
    ports: Vec<u16>
}

many is about being able to parse a single option argument multiple times. You can still use it along with env but since behavior for parsing is going to be different - parsing many times and splitting by comma - you'd use two different parsers, compose them with construct! and use with external.

fn parse_ports(in: String) -> Result<Vec

Replies: 1 comment 13 replies

Comment options

You must be logged in to vote
13 replies
@pacak
Comment options

@teohhanhui
Comment options

@pacak
Comment options

@teohhanhui
Comment options

@pacak
Comment options

Answer selected by teohhanhui
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