adding latest to CLI

This commit is contained in:
2021-11-01 19:37:12 +00:00
parent 41f007c9a5
commit 23eead307a

View File

@@ -1,3 +1,5 @@
import pathlib
import click
import tembo
@@ -22,9 +24,9 @@ def run():
"""
@click.command(options_metavar="<options>")
@click.command(options_metavar="<options>", name="list")
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]
tembo.logger.info(
"%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("--example", is_flag=True, default=False)
def new(scope, inputs, dry_run, example):
"""
r"""
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
"""
# get the name from the tembo config.yml
try:
_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
_cli_verify_name_exists(scope)
# get the scope information from the tembo config.yml
config_scope = {}
@@ -112,7 +110,6 @@ def new(scope, inputs, dry_run, example):
template_filename=config_scope["template_filename"],
template_path=tembo.CONFIG.template_path,
)
if _name_found:
try:
scoped_page = pages.ScopedPageCreator(page_creator_options).create_page()
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:
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
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
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(
"No config.yml found in %s - exiting", tembo.CONFIG.config_path
)
@@ -169,7 +178,7 @@ run.add_command(list_all)
if __name__ == "__main__":
# new(["meeting", "robs presentation", "meeting on gcp"])
new(["meeting", "a", "b", "c", "d", "e"])
new(["meeting", "a", "b", "c", "d"])
# new(["meeting", "robs presentation"])
# pyinstaller