Skip to content

Commit 13caf84

Browse files
committed
fix(cli/init): prettify outputs content
1 parent 62be6e9 commit 13caf84

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/corsair/_app/init.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ def _dump(kind: TemplateKind, path: Path, data: dict) -> None:
4040
if kind == TemplateKind.YAML:
4141
import yaml
4242

43-
yaml.dump(data, f)
43+
yaml.dump(data, f, sort_keys=False, indent=2)
4444
elif kind == TemplateKind.HJSON:
4545
import hjson
4646

47-
hjson.dump(data, f)
47+
hjson.dump(data, f, sort_keys=False, indent=2)
4848
elif kind == TemplateKind.JSON:
4949
import json
5050

51-
json.dump(data, f)
51+
json.dump(data, f, sort_keys=False, indent=2)
5252

5353

5454
def _create_buildspec(kind: TemplateKind) -> csr.BuildSpecification:
@@ -64,10 +64,16 @@ def _create_buildspec(kind: TemplateKind) -> csr.BuildSpecification:
6464

6565
generators = {}
6666
generators["doc_markdown"] = csr.MarkdownGenerator.Config(
67-
show_images=wavedrom_available, wavedrom=csr.WaveDromGenerator.Config(lanes=2)
67+
kind="markdown",
68+
show_images=wavedrom_available,
69+
wavedrom=csr.WaveDromGenerator.Config(lanes=2),
6870
)
6971
if wavedrom_available:
70-
generators["doc_wavedrom"] = csr.WaveDromGenerator.Config(dump_json=True, lanes=2)
72+
generators["doc_wavedrom"] = csr.WaveDromGenerator.Config(
73+
kind="wavedrom",
74+
dump_json=True,
75+
lanes=2,
76+
)
7177

7278
return csr.BuildSpecification(
7379
loader=loader,
@@ -330,5 +336,13 @@ def init(
330336
output.mkdir(parents=True, exist_ok=True)
331337

332338
# Dump files
333-
_dump(TemplateKind.YAML, output / "csrbuild.yaml", _create_buildspec(kind).model_dump(mode="json"))
334-
_dump(kind, output / f"csrmap.{kind.value.lower()}", _create_regmap().model_dump(mode="json"))
339+
_dump(
340+
TemplateKind.YAML,
341+
output / "csrbuild.yaml",
342+
_create_buildspec(kind).model_dump(mode="json", exclude_unset=True),
343+
)
344+
_dump(
345+
kind,
346+
output / f"csrmap.{kind.value.lower()}",
347+
_create_regmap().model_dump(mode="json", exclude_defaults=True, exclude_unset=True),
348+
)

0 commit comments

Comments
 (0)