mirror of
https://github.com/dtomlinson91/tembo.git
synced 2025-12-22 08:05:43 +00:00
adding latest to CLI
This commit is contained in:
47
tembo/cli.py
47
tembo/cli.py
@@ -1,3 +1,5 @@
|
|||||||
|
import pathlib
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
import tembo
|
import tembo
|
||||||
@@ -22,9 +24,9 @@ def run():
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@click.command(options_metavar="<options>")
|
@click.command(options_metavar="<options>", name="list")
|
||||||
def list_all():
|
def list_all():
|
||||||
"""List all names for 'tembo new <name>'."""
|
"""List all scopes defined in the config.yml"""
|
||||||
_all_scopes = [user_scope["name"] for user_scope in tembo.CONFIG.scopes]
|
_all_scopes = [user_scope["name"] for user_scope in tembo.CONFIG.scopes]
|
||||||
tembo.logger.info(
|
tembo.logger.info(
|
||||||
"%s names found in config.yml: '%s'", len(_all_scopes), "', '".join(_all_scopes)
|
"%s names found in config.yml: '%s'", len(_all_scopes), "', '".join(_all_scopes)
|
||||||
@@ -42,25 +44,21 @@ def list_all():
|
|||||||
@click.option("--dry-run", is_flag=True, default=False)
|
@click.option("--dry-run", is_flag=True, default=False)
|
||||||
@click.option("--example", is_flag=True, default=False)
|
@click.option("--example", is_flag=True, default=False)
|
||||||
def new(scope, inputs, dry_run, example):
|
def new(scope, inputs, dry_run, example):
|
||||||
"""
|
r"""
|
||||||
Create a new page.
|
Create a new page.
|
||||||
|
|
||||||
<scope> The name of the scope in the Tembo config.yml.
|
<scope>\n
|
||||||
|
The name of the scope in the config.yml.
|
||||||
|
|
||||||
<inputs> Any input tokens needed in the Tembo config.yml.
|
<inputs>\n
|
||||||
|
Any input token values that are defined in the config.yml for this scope.
|
||||||
|
Accepts multiple inputs separated by a space.
|
||||||
|
|
||||||
Example: tembo new meeting my_presentation
|
Example: tembo new meeting my_presentation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# get the name from the tembo config.yml
|
# get the name from the tembo config.yml
|
||||||
try:
|
_cli_verify_name_exists(scope)
|
||||||
_name_found = scope in [
|
|
||||||
user_scope["name"] for user_scope in tembo.CONFIG.scopes
|
|
||||||
]
|
|
||||||
except TypeError as type_error:
|
|
||||||
# raise error if no scopes are defined
|
|
||||||
tembo.logger.critical("No scopes found in config.yml - exiting")
|
|
||||||
raise SystemExit(1) from type_error
|
|
||||||
|
|
||||||
# get the scope information from the tembo config.yml
|
# get the scope information from the tembo config.yml
|
||||||
config_scope = {}
|
config_scope = {}
|
||||||
@@ -112,7 +110,6 @@ def new(scope, inputs, dry_run, example):
|
|||||||
template_filename=config_scope["template_filename"],
|
template_filename=config_scope["template_filename"],
|
||||||
template_path=tembo.CONFIG.template_path,
|
template_path=tembo.CONFIG.template_path,
|
||||||
)
|
)
|
||||||
if _name_found:
|
|
||||||
try:
|
try:
|
||||||
scoped_page = pages.ScopedPageCreator(page_creator_options).create_page()
|
scoped_page = pages.ScopedPageCreator(page_creator_options).create_page()
|
||||||
except exceptions.BasePathDoesNotExistError as base_path_does_not_exist_error:
|
except exceptions.BasePathDoesNotExistError as base_path_does_not_exist_error:
|
||||||
@@ -147,12 +144,24 @@ def new(scope, inputs, dry_run, example):
|
|||||||
except exceptions.ScopedPageAlreadyExists as scoped_page_already_exists:
|
except exceptions.ScopedPageAlreadyExists as scoped_page_already_exists:
|
||||||
cli_message(f"File {scoped_page_already_exists}")
|
cli_message(f"File {scoped_page_already_exists}")
|
||||||
raise SystemExit(0) from 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
|
|
||||||
click.echo(cli_message(f"Command {scope} not found in config.yml."))
|
|
||||||
raise SystemExit(0)
|
|
||||||
|
|
||||||
|
|
||||||
|
def _cli_verify_name_exists(scope: str) -> None:
|
||||||
|
_name_found = scope in [
|
||||||
|
user_scope["name"] for user_scope in tembo.CONFIG.scopes
|
||||||
|
]
|
||||||
|
if _name_found:
|
||||||
|
return
|
||||||
|
if len(tembo.CONFIG.scopes) > 0:
|
||||||
|
# if the name is missing in the config.yml, raise error
|
||||||
|
cli_message(f"Command {scope} not found in config.yml.")
|
||||||
|
raise SystemExit(0)
|
||||||
# raise error if no config.yml found
|
# raise error if no config.yml found
|
||||||
|
if pathlib.Path(tembo.CONFIG.config_path).exists():
|
||||||
|
tembo.logger.critical(
|
||||||
|
"Config.yml found in %s is empty - exiting", tembo.CONFIG.config_path
|
||||||
|
)
|
||||||
|
else:
|
||||||
tembo.logger.critical(
|
tembo.logger.critical(
|
||||||
"No config.yml found in %s - exiting", tembo.CONFIG.config_path
|
"No config.yml found in %s - exiting", tembo.CONFIG.config_path
|
||||||
)
|
)
|
||||||
@@ -169,7 +178,7 @@ run.add_command(list_all)
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# new(["meeting", "robs presentation", "meeting on gcp"])
|
# new(["meeting", "robs presentation", "meeting on gcp"])
|
||||||
new(["meeting", "a", "b", "c", "d", "e"])
|
new(["meeting", "a", "b", "c", "d"])
|
||||||
# new(["meeting", "robs presentation"])
|
# new(["meeting", "robs presentation"])
|
||||||
|
|
||||||
# pyinstaller
|
# pyinstaller
|
||||||
|
|||||||
Reference in New Issue
Block a user