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
32
33
34
35
36
37
use std::fmt::Display;

use crate::cli_error::CliResult;

/// parser complexities:
///
/// compound flags (-am)
///
/// optional flags
///
/// out of order flags
pub trait Input {
    fn parsed(&self) -> bool;
    fn has_default(&self) -> bool;
    fn parse(&mut self, token: &str) -> CliResult<bool>;
    fn display_name(&self) -> String;
    fn description(&self) -> Option<String>;
    fn type_name(&self) -> InputType;
    fn is_bool_flag(&self) -> bool;

    /// must not return completions that don't start with value, otherwise bash breaks
    fn complete(&mut self, value: &str) -> CliResult<Vec<String>>;
}

#[derive(Debug, PartialEq)]
pub enum InputType {
    Flag,
    Arg,
}

pub type Completor<'a> = Box<dyn FnMut(&str) -> CliResult<Vec<String>> + 'a>;

impl Display for InputType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{:?}", self)
    }
}