start of close tag (#1639)

* start of close tag

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* docs

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* close

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* use local

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2024-03-07 12:35:56 -08:00
committed by GitHub
parent 06f1257071
commit 5a7f12a06d
13 changed files with 204 additions and 129 deletions

View File

@ -420,6 +420,36 @@ impl Args {
}
}
fn get_sketch_group_and_optional_tag(&self) -> Result<(Box<SketchGroup>, Option<String>), KclError> {
let first_value = self.args.first().ok_or_else(|| {
KclError::Type(KclErrorDetails {
message: format!("Expected a SketchGroup as the first argument, found `{:?}`", self.args),
source_ranges: vec![self.source_range],
})
})?;
let sketch_group = if let MemoryItem::SketchGroup(sg) = first_value {
sg.clone()
} else {
return Err(KclError::Type(KclErrorDetails {
message: format!("Expected a SketchGroup as the first argument, found `{:?}`", self.args),
source_ranges: vec![self.source_range],
}));
};
if let Some(second_value) = self.args.get(1) {
let tag: String = serde_json::from_value(second_value.get_json_value()?).map_err(|e| {
KclError::Type(KclErrorDetails {
message: format!("Failed to deserialize String from JSON: {}", e),
source_ranges: vec![self.source_range],
})
})?;
Ok((sketch_group, Some(tag)))
} else {
Ok((sketch_group, None))
}
}
fn get_data_and_optional_tag<T: serde::de::DeserializeOwned>(
&self,
) -> Result<(T, Option<SketchOnFaceTag>), KclError> {
@ -881,10 +911,14 @@ mod tests {
fn_docs.push_str("#### Arguments\n\n");
for arg in internal_fn.args() {
let (format, should_be_indented) = arg.get_type_string().unwrap();
let optional_string = if arg.required { " (REQUIRED)" } else { " (OPTIONAL)" }.to_string();
if let Some(description) = arg.description() {
fn_docs.push_str(&format!("* `{}`: `{}` - {}\n", arg.name, arg.type_, description));
fn_docs.push_str(&format!(
"* `{}`: `{}` - {}{}\n",
arg.name, arg.type_, description, optional_string
));
} else {
fn_docs.push_str(&format!("* `{}`: `{}`\n", arg.name, arg.type_));
fn_docs.push_str(&format!("* `{}`: `{}`{}\n", arg.name, arg.type_, optional_string));
}
if should_be_indented {