generated from cvxgrp/cvxcli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loading standard templates from a file
- Loading branch information
Showing
3 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": "[email protected]:tschm/experiments.git", | ||
"A package (complete with a release process)": "[email protected]:tschm/package.git", | ||
"A paper": "[email protected]: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: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
templates: | ||
marimo_experiments: | ||
url: "[email protected]:tschm/experiments.git" | ||
display_name: "(Marimo) Experiments" | ||
package: | ||
url: "[email protected]:tschm/package.git" | ||
display_name: "A python package" | ||
paper: | ||
url: "[email protected]:tschm/paper.git" | ||
display_name: "A LaTeX document" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters