Interaction between env and many? #168
-
Considering there's no support for splitting an argument by a delimiter value, like clap's There seems to be no way to set multiple values by an environment variable? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 13 replies
-
Not directly but you can always use 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>
}
fn parse_ports(in: String) -> Result<Vec<u16>, String> {
....
}
#[derive(Debug, Clone, Bpaf)]
#[bpaf(options)]
struct Opts {
#[bpaf(external(get_ports))]
ports: Vec<u16>
}
fn get_ports() -> impl Parser<Vec<u16>> {
let by_env = long("ports").env("PORTS").argument("PORTS").parse(parse_ports);
let by_many = long("port").argument("PORT").many();
construct!([by_env, by_many])
} |
Beta Was this translation helpful? Give feedback.
Not directly but you can always use
parse
to your advantage to replicatevalue_delimiter
- getting a single argument and splitting it.many
is about being able to parse a single option argument multiple times. You can still use it along withenv
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 withconstruct!
and use withexternal
.