diff --git a/cli/src/operation_templater.rs b/cli/src/operation_templater.rs index 1282175c2d..fd1192aa53 100644 --- a/cli/src/operation_templater.rs +++ b/cli/src/operation_templater.rs @@ -56,6 +56,9 @@ impl TemplateLanguage<'static> for OperationTemplateLanguage<'_> { OperationTemplatePropertyKind::Core(property) => { template_builder::build_core_method(self, build_ctx, property, function) } + OperationTemplatePropertyKind::Operation(property) => { + build_operation_method(self, build_ctx, property, function) + } OperationTemplatePropertyKind::OperationId(property) => { build_operation_id_method(self, build_ctx, property, function) } @@ -64,6 +67,14 @@ impl TemplateLanguage<'static> for OperationTemplateLanguage<'_> { } impl OperationTemplateLanguage<'_> { + #[allow(unused)] // TODO + fn wrap_operation( + &self, + property: impl TemplateProperty + 'static, + ) -> OperationTemplatePropertyKind { + OperationTemplatePropertyKind::Operation(Box::new(property)) + } + fn wrap_operation_id( &self, property: impl TemplateProperty + 'static, @@ -74,6 +85,7 @@ impl OperationTemplateLanguage<'_> { enum OperationTemplatePropertyKind { Core(CoreTemplatePropertyKind<'static, Operation>), + Operation(Box>), OperationId(Box>), } @@ -81,6 +93,7 @@ impl IntoTemplateProperty<'static, Operation> for OperationTemplatePropertyKind fn try_into_boolean(self) -> Option>> { match self { OperationTemplatePropertyKind::Core(property) => property.try_into_boolean(), + OperationTemplatePropertyKind::Operation(_) => None, OperationTemplatePropertyKind::OperationId(_) => None, } } @@ -105,6 +118,7 @@ impl IntoTemplateProperty<'static, Operation> for OperationTemplatePropertyKind fn try_into_template(self) -> Option>> { match self { OperationTemplatePropertyKind::Core(property) => property.try_into_template(), + OperationTemplatePropertyKind::Operation(_) => None, OperationTemplatePropertyKind::OperationId(property) => Some(property.into_template()), } } @@ -122,6 +136,20 @@ fn build_operation_keyword( .ok_or_else(|| TemplateParseError::no_such_keyword(name, span)) } +fn build_operation_method( + language: &OperationTemplateLanguage, + _build_ctx: &BuildContext, + self_property: impl TemplateProperty + 'static, + function: &FunctionCallNode, +) -> TemplateParseResult { + if let Some(property) = build_operation_keyword_opt(language, self_property, function.name) { + template_parser::expect_no_arguments(function)?; + Ok(property) + } else { + Err(TemplateParseError::no_such_method("Operation", function)) + } +} + fn build_operation_keyword_opt( language: &OperationTemplateLanguage, property: impl TemplateProperty + 'static, diff --git a/docs/templates.md b/docs/templates.md index cbeaec3aeb..dc37115f9d 100644 --- a/docs/templates.md +++ b/docs/templates.md @@ -120,6 +120,11 @@ The following methods are defined. See also the `List` type. * `.join(separator: Template) -> Template` +### Operation type + +This type cannot be printed. All operation keywords are accessible as 0-argument +methods. + ### OperationId type The following methods are defined.