Skip to main content

hyperlane_cli/template/
impl.rs

1use crate::*;
2
3impl FromStr for TemplateType {
4    type Err = TemplateError;
5
6    fn from_str(s: &str) -> Result<Self, Self::Err> {
7        match s.to_lowercase().as_str() {
8            "controller" => Ok(Self::Controller),
9            "domain" => Ok(Self::Domain),
10            "exception" => Ok(Self::Exception),
11            "mapper" => Ok(Self::Mapper),
12            "model" => Ok(Self::Model),
13            "repository" => Ok(Self::Repository),
14            "service" => Ok(Self::Service),
15            "utils" => Ok(Self::Utils),
16            "view" => Ok(Self::View),
17            _ => Err(TemplateError::InvalidTemplateType(s.to_string())),
18        }
19    }
20}
21
22impl TemplateConfig {
23    /// Create a new template configuration
24    ///
25    /// # Arguments
26    ///
27    /// - `TemplateType`: Type of template component
28    /// - `String`: Name of the component
29    /// - `Option<ModelSubType>`: Optional model subtype for model components
30    ///
31    /// # Returns
32    ///
33    /// - `Self`: Configuration instance
34    pub fn new(
35        template_type: TemplateType,
36        component_name: String,
37        model_sub_type: Option<ModelSubType>,
38    ) -> Self {
39        Self {
40            template_type,
41            component_name,
42            model_sub_type,
43            base_directory: "./application".to_string(),
44        }
45    }
46}
47
48impl FromStr for ModelSubType {
49    type Err = TemplateError;
50
51    fn from_str(s: &str) -> Result<Self, Self::Err> {
52        match s.to_lowercase().as_str() {
53            "application" => Ok(Self::Application),
54            "request" => Ok(Self::Request),
55            "response" => Ok(Self::Response),
56            _ => Err(TemplateError::InvalidModelSubType(s.to_string())),
57        }
58    }
59}