Skip to content

Commit 7605675

Browse files
committed
puppet: fix json print for conditional statements
1 parent d60f2be commit 7605675

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

glitch/parsers/puppet.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,13 @@ def process_hash_value(
349349
)
350350
)
351351
for statement in body:
352-
condition.add_statement(statement)
352+
# FIXME: this should probably be more general (e.g. recursive lists)
353+
if isinstance(statement, list):
354+
for s in statement:
355+
condition.add_statement(s)
356+
# Avoids unsupported concepts
357+
elif statement is not None:
358+
condition.add_statement(statement)
353359

354360
if codeelement.elseblock is not None:
355361
condition.else_statement = PuppetParser.__process_codeelement(

glitch/repr/inter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ def add_statement(self, statement: "ConditionalStatement") -> None:
4040
def as_dict(self) -> Dict[str, Any]:
4141
return {
4242
**super().as_dict(),
43-
"statements": [s.as_dict() for s in self.statements],
43+
"statements": [
44+
s.as_dict() if not isinstance(s, str) else s for s in self.statements
45+
],
4446
}
4547

4648

@@ -109,7 +111,9 @@ def as_dict(self) -> Dict[str, Any]:
109111
return {
110112
**super().as_dict(),
111113
"name": self.name,
112-
"value": self.value,
114+
# FIXME: In Puppet code, the value can be a ConditionalStatement.
115+
# The types need to be fixed.
116+
"value": self.value if isinstance(self.value, str) else self.value.to_dict(), # type: ignore
113117
"has_variable": self.has_variable,
114118
"keyvalues": [kv.as_dict() for kv in self.keyvalues],
115119
}

0 commit comments

Comments
 (0)