get_item_from_cli_args_or_select

Function get_item_from_cli_args_or_select 

Source
pub fn get_item_from_cli_args_or_select<'a, CAS, O, OBA, OF>(
    cli_args: &'a [String],
    cli_arg_selector: CAS,
    items: Vec<O>,
    item_find_by_arg: OBA,
) -> Result<Option<O>>
where O: Clone + Debug + Display, CAS: FnMut(&(usize, &String)) -> bool, OBA: Fn(&'a str) -> OF, OF: FnMut(&O) -> bool + 'a,
Expand description

Returns an item derived from CLI args or asks the user to select one.

Priority order:

  1. Tries to find the first CLI arg (by predicate) mapping to an existing item via item_find_by_arg.
  2. Falls back to interactive selection (minimal_select).

Generic over a collection of displayable, cloneable items, so callers can pass any vector of choices.

§Type Parameters

  • CAS Closure filtering (index, &String) CLI arguments.
  • OBA Closure mapping an argument &str into a predicate over &O.
  • OF Predicate produced by OBA used to match an item.

§Errors

  • A CLI argument matches predicate but no corresponding item is found.
  • The interactive selection fails (see minimal_select).