Skip to content

Commit

Permalink
Making the nested proto field drilldowns more generic
Browse files Browse the repository at this point in the history
They had unique logic specifically for `trigger.` but that means that they wont work for any other nested proto in the future.
  • Loading branch information
AsherGlick committed Sep 30, 2023
1 parent 031d6a4 commit 2bfda56
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions xml_converter/generators/code_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,7 @@ def generate_cpp_variable_data(
xml_fields.append(lowercase(x, delimiter=""))
default_xml_field = fieldval['xml_fields'][0]

# TODO: this should handle more then just `trigger.` variants
if fieldval["protobuf_field"].startswith("trigger"):
proto_drilldown_calls = ".trigger()"
# TODO this would not properly catch trigger.something.ourvariable
protobuf_field = fieldval["protobuf_field"].split('.')[1]
else:
proto_drilldown_calls = ""
protobuf_field = fieldval["protobuf_field"]
proto_drilldown_calls, protobuf_field = split_field_into_drilldown(fieldval["protobuf_field"])

if fieldval.get("uses_file_path", False):
args.append("base_dir")
Expand Down Expand Up @@ -471,14 +464,7 @@ def write_attribute(self, output_directory: str) -> None:
metadata[filepath] = self.data[filepath].metadata
attribute_name = attribute_name_from_markdown_data(metadata[filepath]['name'])

# TODO this should handle more then just `trigger.` variants
if metadata[filepath]["protobuf_field"].startswith("trigger"):
proto_drilldown_calls = ".trigger()"
# TODO this would not properly catch trigger.something.ourvariable
protobuf_field = metadata[filepath]["protobuf_field"].split('.')[1]
else:
proto_drilldown_calls = ""
protobuf_field = metadata[filepath]["protobuf_field"]
proto_drilldown_calls, protobuf_field = split_field_into_drilldown(metadata[filepath]["protobuf_field"])

if metadata[filepath]['type'] == "MultiflagValue":
for flag in metadata[filepath]['flags']:
Expand Down Expand Up @@ -754,6 +740,22 @@ def generate_auto_docs(self, metadata: Dict[str, SchemaType], content: Dict[str,
return template.render(field_rows=field_rows), field_rows


################################################################################
# split_field_into_drilldown
#
# Splits the field string into a cpp drilldown function call stack and the
# final proto field name.
# EG:
# field: "trigger.range"
# returns: (".trigger()", "range")
################################################################################
def split_field_into_drilldown(field: str) -> Tuple[str, str]:
components = field.split(".")
proto_drilldown_calls = "".join([".{}()".format(x) for x in components[:-1]])
protobuf_field = components[-1]
return proto_drilldown_calls, protobuf_field


############################################################################
# attribute_name_from_markdown_data
#
Expand Down

0 comments on commit 2bfda56

Please sign in to comment.