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
61
62
63
64
65
66
67
use crate::Result;
use std::{env::VarError, num::ParseIntError};
use strum::ParseError;

#[derive(thiserror::Error, Debug)]
pub enum DnsCommandError {
    #[error("Domain name missing")]
    DomainNameMissing,

    #[error("Too many parameter for {0}")]
    TooManyParameters(String),

    #[error("Wrong subcommand {0}")]
    WrongSubCommand(&'static str),

    #[error("Missing subcommand")]
    MissingSubCommand,
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
    #[error("Dns: {0}")]
    Dns(#[from] DnsCommandError),

    #[error("Strum: {0}")]
    Strum(#[from] ParseError),

    #[error("Parse transip command: {0}")]
    ParseTransipCommand(String),

    #[error("Parse product command: {0}")]
    ParseProductCommand(String),

    #[error("Parse domain command: {0}")]
    ParseDomainCommand(String),

    #[error("Parse dns command: {0}")]
    ParseDnsCommand(String),

    #[error("Parse vps command: {0}")]
    ParseVpsCommand(String),

    #[error("Parse invoice command: {0}")]
    ParseInvoiceCommand(String),

    #[error("IO: {0}")]
    IO(#[from] std::io::Error),

    #[error("Variable: {0}")]
    Var(#[from] VarError),

    #[error("Parse: {0}")]
    ParseInt(#[from] ParseIntError),
}

pub trait ErrorExt<T, E> {
    fn err_into(self) -> Result<T>;
}

impl<T, E> ErrorExt<T, E> for std::result::Result<T, E>
where
    E: Into<Error>,
{
    fn err_into(self) -> Result<T> {
        self.map_err(Into::into)
    }
}