Skip to content

Commit c8ab382

Browse files
committed
Print JSON without additional indentation by default
Because vertical screen space is valuable, compact JSON output formatting is a better default. However, it is still possible to pretty-print the JSON as before with the new --pretty option.
1 parent 04304c6 commit c8ab382

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

src/simple_safe/console.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ def activate_logging():
7272

7373

7474
def get_json_data_renderable(
75-
data: dict[str, Any], indent: Optional[int] = 2
75+
data: dict[str, Any], pretty: bool = False
7676
) -> "RenderableType":
7777
from rich.json import JSON
7878

7979
return JSON.from_data(
8080
data,
8181
default=hexbytes_json_encoder,
82-
indent=JSON_INDENT_LEVEL,
82+
indent=2 if pretty else None,
8383
)
8484

8585

src/simple_safe/params.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ def build_safetx(f: FC) -> FC:
117117
make_option(chain_id_option_info, cls=optgroup.option),
118118
safe_version,
119119
optgroup.option("--safe-nonce", type=int, help="Safe nonce"),
120+
click.option(
121+
"--pretty",
122+
is_flag=True,
123+
help="Pretty print EIP-712 message JSON",
124+
),
120125
]
121126
):
122127
f = option(f)

src/simple_safe/safe.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def build_abi_call(
203203
function: str,
204204
operation: int,
205205
output: Optional[typing.TextIO],
206+
pretty: bool,
206207
rpc: Optional[str],
207208
safe_address: str,
208209
safe_nonce: Optional[int],
@@ -238,6 +239,7 @@ def build_abi_call(
238239
value=value,
239240
operation=SafeOperation(operation).value,
240241
output=output,
242+
pretty=pretty,
241243
)
242244

243245

@@ -256,6 +258,7 @@ def build_custom(
256258
data: str,
257259
operation: int,
258260
output: Optional[typing.TextIO],
261+
pretty: bool,
259262
rpc: Optional[str],
260263
safe_address: str,
261264
safe_nonce: Optional[int],
@@ -293,7 +296,7 @@ def build_custom(
293296
)
294297
eip712_data = safetx.to_eip712_message(safe)
295298
output_console = get_output_console(output)
296-
output_console.print(get_json_data_renderable(eip712_data))
299+
output_console.print(get_json_data_renderable(eip712_data, pretty))
297300

298301

299302
@build.command(name="erc20-call")
@@ -314,6 +317,7 @@ def build_erc20_call(
314317
chain_id: Optional[int],
315318
function: str,
316319
output: Optional[typing.TextIO],
320+
pretty: bool,
317321
rpc: Optional[str],
318322
safe_address: str,
319323
safe_nonce: Optional[int],
@@ -351,6 +355,7 @@ def build_erc20_call(
351355
value=value,
352356
operation=SafeOperation.CALL.value,
353357
output=output,
358+
pretty=pretty,
354359
)
355360

356361

@@ -365,6 +370,7 @@ def build_safe_call(
365370
chain_id: Optional[int],
366371
function: str,
367372
output: Optional[typing.TextIO],
373+
pretty: bool,
368374
rpc: Optional[str],
369375
safe_address: str,
370376
safe_nonce: Optional[int],
@@ -397,6 +403,7 @@ def build_safe_call(
397403
value=value,
398404
operation=SafeOperation.CALL.value,
399405
output=output,
406+
pretty=pretty,
400407
)
401408

402409

src/simple_safe/workflows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def build_contract_call_safetx(
6363
value: str,
6464
operation: int,
6565
output: Optional[TextIO],
66+
pretty: bool,
6667
):
6768
"""Print a SafeTx that represents a contract call."""
6869
from web3.constants import CHECKSUM_ADDRESSS_ZERO
@@ -91,7 +92,7 @@ def build_contract_call_safetx(
9192
)
9293
output_console = get_output_console(output)
9394
output_console.print(
94-
get_json_data_renderable(safetx.to_eip712_message(safe)),
95+
get_json_data_renderable(safetx.to_eip712_message(safe), pretty),
9596
)
9697

9798

0 commit comments

Comments
 (0)