feat: create toml to stdout by default

This commit is contained in:
张泊明518370910136 2025-03-15 02:37:08 -04:00
parent b43a25285e
commit 6630612915
GPG Key ID: D47306D7062CDA9D

View File

@ -1,5 +1,6 @@
import json
from pathlib import Path
from typing import Optional
import rtoml
import typer
@ -20,11 +21,12 @@ app = typer.Typer(add_completion=False)
@app.command()
def create(toml_path: Path) -> None:
def create(
toml_path: Annotated[Optional[Path], typer.Argument()] = None,
) -> None:
"""
Create a new JOJ3 task toml config file
"""
logger.info(f"Creating task toml file {toml_path}")
answers = load_joj3_task_toml_answers()
answers_dict = answers.model_dump(mode="json", by_alias=True)
logger.debug(f"Got answers: {answers_dict}")
@ -32,7 +34,13 @@ def create(toml_path: Path) -> None:
result_dict = task_model.model_dump(
mode="json", by_alias=True, exclude_none=True, exclude_unset=True
)
toml_path.write_text(rtoml.dumps(result_dict))
toml_str = rtoml.dumps(result_dict)
if toml_path is None:
logger.info("Writing task toml to stdout")
print(toml_str)
else:
logger.info(f"Creating task toml file {toml_path}")
toml_path.write_text(toml_str)
@app.command()