diff --git a/src/cvx/cradle/cli.py b/src/cvx/cradle/cli.py index 3ea3254..a0b7f43 100644 --- a/src/cvx/cradle/cli.py +++ b/src/cvx/cradle/cli.py @@ -28,6 +28,16 @@ from .utils.shell import run_shell_command +def load_templates(yaml_path: Path) -> dict[str, str]: + """ + Load templates from YAML file and return a dictionary mapping display names to URLs. + """ + with open(yaml_path) as f: + config = yaml.safe_load(f) + + return {details["display_name"]: details["url"] for template_name, details in config["templates"].items()} + + def append_to_yaml_file(new_data, file_path): # Check if the file exists if os.path.exists(file_path): @@ -68,21 +78,17 @@ def cli(template: str = None, dst_path: str = None, vcs_ref: str | None = None, logger.info("cradle will ask a group of questions to create a repository for you") if template is None: - # which template you want to pick? - templates = { - "(Marimo) Experiments": "git@github.com:tschm/experiments.git", - "A package (complete with a release process)": "git@github.com:tschm/package.git", - "A paper": "git@github.com:tschm/paper.git", - } - - # result is the value related to the key you pick + # Load templates from YAML file + yaml_path = Path(__file__).parent / "templates.yaml" # Adjust path as needed + templates = load_templates(yaml_path) + + # Let user select from the display names result = questionary.select( "What kind of project do you want to create?", choices=list(templates.keys()), ).ask() template = templates[result] - remove_path = False # Create a random path if not dst_path: diff --git a/src/cvx/cradle/templates.yaml b/src/cvx/cradle/templates.yaml new file mode 100644 index 0000000..109d6a3 --- /dev/null +++ b/src/cvx/cradle/templates.yaml @@ -0,0 +1,10 @@ +templates: + marimo_experiments: + url: "git@github.com:tschm/experiments.git" + display_name: "(Marimo) Experiments" + package: + url: "git@github.com:tschm/package.git" + display_name: "A python package" + paper: + url: "git@github.com:tschm/paper.git" + display_name: "A LaTeX document" diff --git a/src/tests/test_cli.py b/src/tests/test_cli.py index 9ce4f9b..7becede 100644 --- a/src/tests/test_cli.py +++ b/src/tests/test_cli.py @@ -32,7 +32,7 @@ def ask(self): def test_no_template(mock_context, mocker, tmp_path, mock_run_shell_command): - mocker.patch("cvx.cradle.cli.questionary.select", return_value=Answer("A paper")) + mocker.patch("cvx.cradle.cli.questionary.select", return_value=Answer("A LaTeX document")) mocker.patch("cvx.cradle.cli.ask", return_value=mock_context) mocker.patch("cvx.cradle.cli.copier.run_copy", return_value=None) cli(dst_path=str(tmp_path)) @@ -40,7 +40,7 @@ def test_no_template(mock_context, mocker, tmp_path, mock_run_shell_command): def test_runtime_error(mock_context, mocker, tmp_path): - mocker.patch("cvx.cradle.cli.questionary.select", return_value=Answer("A paper")) + mocker.patch("cvx.cradle.cli.questionary.select", return_value=Answer("A LaTeX document")) mocker.patch("cvx.cradle.cli.ask", return_value=mock_context) mocker.patch("cvx.cradle.cli.copier.run_copy", return_value=None) mocker.patch("cvx.cradle.cli.run_shell_command", side_effect=RuntimeError("An error occurred"))