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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use std::env::args;
use std::ffi::OsString;
use std::path::Path;

pub enum MsgType<'a> {
    Help,
    InvalidArgumentCount(usize),
    UnknownOption(&'a String),
}

pub struct MsgPrinter {
    help_msg: String,
}

impl MsgPrinter {
    pub fn new(help_msg: String) -> MsgPrinter {
        Self { help_msg }
    }

    pub fn show_msg(&self, msg_type: MsgType) -> Result<(), String> {
        match msg_type {
            MsgType::Help => {
                println!("{}", self.help_msg);
                Ok(())
            }
            MsgType::InvalidArgumentCount(count) => {
                Err(format!("Invalid argument count: {}", count))
            }
            MsgType::UnknownOption(option) => Err(format!("Unknown option: {}", option)),
        }
    }
}

pub fn get_file_name() -> String {
    let file_path = args().next().unwrap();
    let file_name = OsString::from(Path::new(&file_path).file_name().unwrap())
        .into_string()
        .unwrap();
    file_name
}

pub fn get_args_without_self_path() -> Vec<String> {
    let args = args();
    let mut c: Vec<String> = args.collect();
    c.remove(0);
    c
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub struct Pair<T1, T2> {
    a: T1,
    b: T2,
}

impl<T1, T2> Pair<T1, T2> {
    #[inline]
    pub fn new(a: T1, b: T2) -> Pair<T1, T2> {
        Self { a, b }
    }
}