cli_rs/
input.rs

1use std::fmt::Display;
2
3use crate::cli_error::CliResult;
4
5/// parser complexities:
6///
7/// compound flags (-am)
8///
9/// optional flags
10///
11/// out of order flags
12pub trait Input {
13    fn parsed(&self) -> bool;
14    fn has_default(&self) -> bool;
15    fn parse(&mut self, token: &str) -> CliResult<bool>;
16    fn display_name(&self) -> String;
17    fn description(&self) -> Option<String>;
18    fn type_name(&self) -> InputType;
19    fn is_bool_flag(&self) -> bool;
20
21    /// must not return completions that don't start with value, otherwise bash breaks
22    fn complete(&mut self, value: &str) -> CliResult<Vec<String>>;
23}
24
25#[derive(Debug, PartialEq)]
26pub enum InputType {
27    Flag,
28    Arg,
29}
30
31pub type Completor<'a> = Box<dyn FnMut(&str) -> CliResult<Vec<String>> + 'a>;
32
33impl Display for InputType {
34    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35        write!(f, "{:?}", self)
36    }
37}