1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/// 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<Vec<u16>, ParseIntError> {
    s.split(',')
        .map(u16::from_str)
        .collect::<Result<Vec<_>, _>>()
}

fn flatten_vec(vv: Vec<Vec<u16>>) -> Vec<u16> {
    vv.into_iter().flatten().collect()
}

#[derive(Debug, Clone, Bpaf)]
#[allow(dead_code)]
struct Opts {
    #[bpaf(
        long,
        argument::<String>("PORTS"),
        parse(split_and_parse),
        many,
        map(flatten_vec)
    )]
    /// Comma separated list of ports
    ports: Vec<u16>,
}

fn main() {
    println!("{:?}", opts().to_options().run());
}