Skip to content

Commit 282856d

Browse files
authored
Merge pull request #282 from input-output-hk/add_output_format_option
feat(conway_gov_drep_group): add support for `--output-hex`
2 parents 23877fc + 70afe70 commit 282856d

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

cardano_clusterlib/conway_gov_drep_group.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pathlib as pl
55

66
from cardano_clusterlib import clusterlib_helpers
7+
from cardano_clusterlib import exceptions
78
from cardano_clusterlib import helpers
89
from cardano_clusterlib import structs
910
from cardano_clusterlib import types as itp
@@ -15,6 +16,25 @@ class ConwayGovDrepGroup:
1516
def __init__(self, clusterlib_obj: "itp.ClusterLib") -> None:
1617
self._clusterlib_obj = clusterlib_obj
1718
self._group_args = ("governance", "drep")
19+
self._has_output_hex_prop: bool | None = None
20+
21+
@property
22+
def _has_output_hex(self) -> bool:
23+
"""Check if `drep id` has a `--output-hex` option."""
24+
if self._has_output_hex_prop is not None:
25+
return self._has_output_hex_prop
26+
27+
err = ""
28+
try:
29+
self._clusterlib_obj.cli(
30+
["cardano-cli", "conway", "governance", "drep", "id", "--output-hex"],
31+
add_default_args=False,
32+
)
33+
except exceptions.CLIError as excp:
34+
err = str(excp)
35+
36+
self._has_output_hex_prop = "Invalid option" not in err
37+
return self._has_output_hex_prop
1838

1939
def _get_cred_args(
2040
self,
@@ -94,7 +114,13 @@ def get_id(
94114
raise AssertionError(msg)
95115

96116
if out_format:
97-
cli_args.extend(["--output-format", str(out_format)])
117+
if out_format not in ("hex", "bech32"):
118+
msg = f"Invalid output format: {out_format} (expected 'hex' or 'bech32')."
119+
raise AssertionError(msg)
120+
if self._has_output_hex:
121+
cli_args.append(f"--output-{out_format}")
122+
else:
123+
cli_args.extend(["--output-format", str(out_format)])
98124

99125
drep_id = (
100126
self._clusterlib_obj.cli(

0 commit comments

Comments
 (0)