hyperlane_cli/template/
impl.rs1use super::*;
2
3impl FromStr for TemplateType {
4 type Err = TemplateError;
5
6 fn from_str(s: &str) -> Result<Self, Self::Err> {
16 match s.to_lowercase().as_str() {
17 TEMPLATE_TYPE_CONTROLLER => Ok(Self::Controller),
18 TEMPLATE_TYPE_DOMAIN => Ok(Self::Domain),
19 TEMPLATE_TYPE_EXCEPTION => Ok(Self::Exception),
20 TEMPLATE_TYPE_MAPPER => Ok(Self::Mapper),
21 TEMPLATE_TYPE_MODEL => Ok(Self::Model),
22 TEMPLATE_TYPE_REPOSITORY => Ok(Self::Repository),
23 TEMPLATE_TYPE_SERVICE => Ok(Self::Service),
24 TEMPLATE_TYPE_UTILS => Ok(Self::Utils),
25 TEMPLATE_TYPE_VIEW => Ok(Self::View),
26 _ => Err(TemplateError::InvalidTemplateType(s.to_string())),
27 }
28 }
29}
30
31impl TemplateConfig {
32 pub fn new(
44 template_type: TemplateType,
45 component_name: String,
46 model_sub_type: Option<ModelSubType>,
47 ) -> Self {
48 Self {
49 template_type,
50 component_name,
51 model_sub_type,
52 base_directory: TEMPLATE_CONFIG_BASE_DIRECTORY.to_string(),
53 }
54 }
55}
56
57impl FromStr for ModelSubType {
58 type Err = TemplateError;
59
60 fn from_str(s: &str) -> Result<Self, Self::Err> {
70 match s.to_lowercase().as_str() {
71 MODEL_SUB_TYPE_APPLICATION => Ok(Self::Application),
72 MODEL_SUB_TYPE_REQUEST => Ok(Self::Request),
73 MODEL_SUB_TYPE_RESPONSE => Ok(Self::Response),
74 _ => Err(TemplateError::InvalidModelSubType(s.to_string())),
75 }
76 }
77}