/// To parse comma separated values it's easier to treat them as strings use bpaf::*; use std::{num::ParseIntError, str::FromStr}; fn split_and_parse(s: String) -> Result, ParseIntError> { s.split(',') .map(u16::from_str) .collect::, _>>() } fn flatten_vec(vv: Vec>) -> Vec { vv.into_iter().flatten().collect() } #[derive(Debug, Clone, Bpaf)] #[allow(dead_code)] struct Opts { #[bpaf( long, argument::("PORTS"), parse(split_and_parse), many, map(flatten_vec) )] /// Comma separated list of ports ports: Vec, } fn main() { println!("{:?}", opts().to_options().run()); }