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 config;
mod deployment;
mod ideascale;

use clap::Parser;
use config::ConfigValidateCommand;
use deployment::CheckError;
use deployment::DeploymentValidateCommand;
pub use ideascale::Error as IdeascaleError;
use ideascale::IdeascaleValidateCommand;
use thiserror::Error;

#[derive(Parser, Debug)]
pub enum ValidateCommand {
    Ideascale(IdeascaleValidateCommand),
    Deployment(DeploymentValidateCommand),
    Config(ConfigValidateCommand),
}

impl ValidateCommand {
    pub fn exec(self) -> Result<(), Error> {
        match self {
            Self::Ideascale(ideascale) => ideascale.exec().map_err(Into::into),
            Self::Deployment(deployment) => deployment.exec().map_err(Into::into),
            Self::Config(config) => config.exec().map_err(Into::into),
        }
    }
}

#[derive(Debug, Error)]
pub enum Error {
    #[error(transparent)]
    Config(#[from] config::Error),
    #[error(transparent)]
    Deployment(#[from] CheckError),
    #[error(transparent)]
    Ideascale(#[from] ideascale::Error),
}