Expand description

Structure groups: --foo --foo-1 ARG1 --foo-2 ARG2 --foo-3 ARG3

Groups of options that can be specified multiple times. All such groups should be kept without overwriting previous one.

 $ prometheus_sensors_exporter \
     \
     `# 2 physical sensors located on physycial different i2c bus or address` \
     --sensor \
         --sensor-device=tmp102 \
         --sensor-name="temperature_tmp102_outdoor" \
         --sensor-i2c-bus=0 \
         --sensor-i2c-address=0x48 \
     --sensor \
         --sensor-device=tmp102 \
         --sensor-name="temperature_tmp102_indoor" \
         --sensor-i2c-bus=1 \
         --sensor-i2c-address=0x49 \
Combinatoric usage
#[derive(Debug, Clone)]
pub struct Options {
    switch: bool,
    multi: Vec<Rect>,
}

#[derive(Debug, Clone)]
struct Rect {
    item: (),
    width: usize,
    height: usize,
    painted: bool,
}

fn multi() -> impl Parser<Rect> {
    let item = long("rect").req_flag(());
    let width = long("width").argument::<usize>("PX");
    let height = long("height").argument::<usize>("PX");
    let painted = long("painted").switch();
    construct!(Rect {
        item,
        width,
        height,
        painted,
    })
    .adjacent()
}

pub fn options() -> OptionParser<Options> {
    let switch = short('s').switch();
    let multi = multi().many();
    construct!(Options { multi, switch }).to_options()
}
Examples

Order of items within the rectangle is not significant and you can have several of them

% app --rect --width 10 --height 10 --rect --height 10 --width 10
Options { switch: false, multi: [Rect { item: (), width: 10, height: 10, painted: false }, Rect { item: (), width: 10, height: 10, painted: false }] }

You can have optional values that belong to the group inside and outer flags in the middle

% app --rect --width 10 --painted --height 10 -s --rect --height 10 --width 10
Options { switch: true, multi: [Rect { item: (), width: 10, height: 10, painted: true }, Rect { item: (), width: 10, height: 10, painted: false }] }

But with adjacent they cannot interleave

% app --rect --rect --width 10 --painted --height 10 --height 10 --width 10
--rect is not expected in this context