Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the nested proto field drilldowns more generic #174

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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