summaryrefslogtreecommitdiff
path: root/src/lib.rs
blob: 0a2954d6877d256a9e5312afeec99596a59dae73 (plain) (blame)
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
38
mod query;
mod switchboard;
mod value;

pub use query::*;
pub use switchboard::*;
pub use value::*;

use log::*;


pub enum SwitchName {
    Short(char),
    Long(String),
}

impl std::fmt::Display for SwitchName {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
        match self {
            SwitchName::Short(c) => write!(f, "-{c}"),
            SwitchName::Long(s) => write!(f, "--{s}"),
        }
    }
}

pub enum SwitchboardError {
    Malformed(String),
    MissingNamed(String),
    MissingPositional(String),
    // String is the debug name of the switch
    Repeated(String),
}

fn validate_name(name: &str) {
    if !name.chars().all(|c| c.is_ascii_lowercase() || c.is_digit(10) || c == '-') {
        log::fatal!("Invalid name for argument: {name:?}");
    }
}