mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 10:16:02 +00:00
adding latest
This commit is contained in:
12
tembo/cli.py
12
tembo/cli.py
@@ -122,8 +122,12 @@ def new(scope, inputs, dry_run, example):
|
||||
tembo.logger.critical(template_file_not_found_error.args[0])
|
||||
raise SystemExit(1) from template_file_not_found_error
|
||||
|
||||
scoped_page.save_to_disk(dry_run=dry_run)
|
||||
raise SystemExit(0)
|
||||
try:
|
||||
scoped_page.save_to_disk(dry_run=dry_run)
|
||||
raise SystemExit(0)
|
||||
except exceptions.ScopedPageAlreadyExists as scoped_page_already_exists:
|
||||
cli_message(f"File {scoped_page_already_exists}")
|
||||
raise SystemExit(0) from scoped_page_already_exists
|
||||
if not _name_found and len(tembo.CONFIG.scopes) > 0:
|
||||
# if the name is missing in the config.yml, raise error
|
||||
tembo.logger.warning("Command %s not found in config.yml - exiting", scope)
|
||||
@@ -136,6 +140,10 @@ def new(scope, inputs, dry_run, example):
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def cli_message(message: str) -> None:
|
||||
click.echo(f"[TEMBO] {message} 🐘")
|
||||
|
||||
|
||||
run.add_command(new)
|
||||
run.add_command(list_all)
|
||||
|
||||
|
||||
@@ -11,3 +11,7 @@ class BasePathDoesNotExistError(Exception):
|
||||
|
||||
class TemplateFileNotFoundError(Exception):
|
||||
"""Raised if the template file does not exist."""
|
||||
|
||||
|
||||
class ScopedPageAlreadyExists(Exception):
|
||||
"""Raised if the scoped page file already exists."""
|
||||
|
||||
@@ -74,7 +74,8 @@ class PageCreator:
|
||||
else self.options.extension
|
||||
)
|
||||
except IndexError:
|
||||
# REVIEW: can this be removed now this is not called anywhere else?
|
||||
# REVIEW: try putting a . in the config yaml and see what error is raised
|
||||
# this is no longer generic it just gets the full path to the file.
|
||||
# IndexError means the path is not a file, just a path
|
||||
return path_to_file
|
||||
# return path with a file
|
||||
@@ -88,7 +89,9 @@ class PageCreator:
|
||||
self.options.template_path
|
||||
).expanduser()
|
||||
else:
|
||||
converted_template_path = pathlib.Path()
|
||||
converted_template_path = (
|
||||
pathlib.Path(self.options.base_path).expanduser() / ".templates"
|
||||
)
|
||||
|
||||
file_loader = jinja2.FileSystemLoader(converted_template_path)
|
||||
env = jinja2.Environment(loader=file_loader, autoescape=True)
|
||||
@@ -277,19 +280,21 @@ class ScopedPage(Page):
|
||||
SystemExit: Exit code 0 if dry run is `True`, page is successfully saved
|
||||
or if page already exists.
|
||||
"""
|
||||
# TODO: move this functionality to the CLI so the page is created and the message
|
||||
# returned to the user from the CLI.
|
||||
if dry_run:
|
||||
tembo.logger.info("%s will be created", self.path)
|
||||
raise SystemExit(0)
|
||||
# create the parent directories
|
||||
scoped_note_file = pathlib.Path(self.path)
|
||||
scoped_note_file.parents[0].mkdir(parents=True, exist_ok=True)
|
||||
if not scoped_note_file.exists():
|
||||
with scoped_note_file.open("w", encoding="utf-8") as scoped_page:
|
||||
scoped_page.write(self.page_content)
|
||||
tembo.logger.info("Saved %s to disk", self.path)
|
||||
else:
|
||||
tembo.logger.info("%s already exists - skipping.", self.path)
|
||||
raise SystemExit(0)
|
||||
if scoped_note_file.exists():
|
||||
raise exceptions.ScopedPageAlreadyExists(f"{self.path} already exists")
|
||||
|
||||
with scoped_note_file.open("w", encoding="utf-8") as scoped_page:
|
||||
scoped_page.write(self.page_content)
|
||||
# TODO: pass this back somehow
|
||||
tembo.logger.info("Saved %s to disk", self.path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user