Skip to content

Commit 2c3a665

Browse files
add descriptions to each option of SerializerOptions, DeserializerOptions and FormatterOptions
1 parent ea2697a commit 2c3a665

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

cli/hcl_to_json.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def main():
6868
parser.add_argument(
6969
"--no-explicit-blocks",
7070
action="store_true",
71-
help="Disable explicit block markers",
71+
help="Disable explicit block markers. Note: round-trip through json_to_hcl is NOT supported with this option.",
7272
)
7373
parser.add_argument(
7474
"--no-preserve-heredocs",
@@ -88,7 +88,7 @@ def main():
8888
parser.add_argument(
8989
"--strip-string-quotes",
9090
action="store_true",
91-
help="Strip surrounding double-quotes from serialized string values",
91+
help="Strip surrounding double-quotes from serialized string values. Note: round-trip through json_to_hcl is NOT supported with this option.",
9292
)
9393

9494
# JSON output formatting

hcl2/deserializer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@
6363
class DeserializerOptions:
6464
"""Options controlling how Python dicts are deserialized into LarkElement trees."""
6565

66+
# Convert heredoc values (<<EOF...EOF) to regular escaped strings during
67+
# deserialization. When False, heredoc syntax is preserved as-is.
6668
heredocs_to_strings: bool = False
69+
# Convert multi-line escaped strings (containing \n) back into heredoc
70+
# syntax (<<EOF...EOF) during deserialization.
6771
strings_to_heredocs: bool = False
72+
# Use colon (:) instead of equals (=) as the separator in object elements.
6873
object_elements_colon: bool = False
74+
# Append a trailing comma after each object element.
6975
object_elements_trailing_comma: bool = True
7076
# with_comments: bool = False # TODO
7177

hcl2/formatter.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@
3232
class FormatterOptions:
3333
"""Options controlling whitespace formatting of LarkElement trees."""
3434

35+
# Number of spaces per indentation level.
3536
indent_length: int = 2
37+
# Use multi-line format for empty blocks (opening brace on same line,
38+
# closing brace on next). When False, empty blocks collapse to "{}".
3639
open_empty_blocks: bool = True
40+
# Use multi-line format for empty objects. When False, empty objects
41+
# collapse to "{}".
3742
open_empty_objects: bool = False
43+
# Use multi-line format for empty tuples. When False, empty tuples
44+
# collapse to "[]".
3845
open_empty_tuples: bool = False
39-
46+
# Pad attribute equals signs so they align vertically within a block body.
4047
vertically_align_attributes: bool = True
48+
# Pad object element equals/colons so they align vertically within an object.
4149
vertically_align_object_elements: bool = True
4250

4351

hcl2/utils.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,26 @@
1111
class SerializationOptions:
1212
"""Options controlling how LarkElement trees are serialized to Python dicts."""
1313

14+
# Include __comments__ and __inline_comments__ keys in the output.
1415
with_comments: bool = True
16+
# Add __start_line__ and __end_line__ metadata to each block/attribute.
1517
with_meta: bool = False
18+
# Serialize nested objects as inline HCL strings (e.g. "${{key = value}}")
19+
# instead of Python dicts.
1620
wrap_objects: bool = False
21+
# Serialize tuples as inline HCL strings (e.g. "${[1, 2, 3]}")
22+
# instead of Python lists.
1723
wrap_tuples: bool = False
24+
# Add __is_block__ markers to distinguish blocks from plain objects.
25+
# Note: round-trip through from_dict/dumps is NOT supported WITHOUT this option.
1826
explicit_blocks: bool = True
27+
# Keep heredoc syntax (<<EOF...EOF) in output. When False, heredocs are
28+
# converted to regular escaped strings.
1929
preserve_heredocs: bool = True
30+
# Wrap all binary/unary operations in parentheses for explicit precedence.
2031
force_operation_parentheses: bool = False
32+
# Keep scientific notation for floats (e.g. 1e10). When False, expand to
33+
# standard decimal form.
2134
preserve_scientific_notation: bool = True
2235
# Remove surrounding double-quotes from serialized string values,
2336
# producing backwards-compatible output (e.g. "hello" instead of '"hello"').

0 commit comments

Comments
 (0)