aboutsummaryrefslogtreecommitdiff
path: root/arg_picker/src/builtin/pick_bool.rs
blob: ccc4424c80b26918841f40d61a5ff84ba9e17c6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::parselib::{FlagMatcher, Matcher};
use crate::pickable_needed::*;

impl<'a> Pickable<'a> for bool {
    fn get_attr(_: &'a PickerArg<'a, Self>) -> PickerArgAttr {
        PickerArgAttr::Flag
    }

    fn tag(ctx: TagPhaseContext) -> Vec<usize> {
        FlagMatcher::match_all(ctx.into())
    }

    fn pick(raw_strs: &[&str]) -> PickerArgResult<Self> {
        if raw_strs.is_empty() {
            // No matching flag found — signal NotFound so the fallback chain
            // (default → route) gets a chance to run.
            PickerArgResult::NotFound
        } else {
            PickerArgResult::Parsed(true)
        }
    }
}