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
use argh::FromArgs;

#[derive(Debug, FromArgs)]
/// I need to explain this, I guess
///
/// Source at https://github.com/Canop/csv2svg
pub struct Args {
    #[argh(switch, short = 'v')]
    /// print the version
    pub version: bool,

    #[argh(option, short = 'f')]
    /// output format: "svg" or "html"
    pub format: Option<Format>,
}

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Format {
    Svg,
    Html,
}

impl std::str::FromStr for Format {
    type Err = String;
    fn from_str(s: &str) -> Result<Self, String> {
        match s.to_lowercase().as_ref() {
            "s" | "svg" => Ok(Self::Svg),
            "h" | "html" => Ok(Self::Html),
            _ => Err(format!("unrecognized format {:?}", s)),
        }
    }
}