Commit e6f38685 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[scripts][editor_cli] Move environment cache update in option

This allows for not calling the update process when --help is
passed and allow more fine grained control of which sub command
does it. For example, it doesn't make sense to create the cash
if the refresh_env sub-command is called.
parent 1a5a2f29
......@@ -62,6 +62,25 @@ def dump_environments(environments_file_path):
logger.info("Done")
def setup_environment_cache(ctx, param, value):
"""Click option callback to setup environment cache"""
if not value:
environments = ctx.meta["environments"]
if not os.path.exists(environments):
dump_environments(environments)
refresh_environment_cache_flag = click.option(
"--no-check-env",
is_flag=True,
expose_value=False,
default=False,
help="Do not check for environment cache",
callback=setup_environment_cache,
)
START_EPILOG = """\b
Example:
$ beat editor start
......@@ -95,9 +114,6 @@ def editor(ctx, environments):
logger = setup_logger("beat.editor", ctx.meta["verbosity"])
logger.info("BEAT prefix set to `%s'", ctx.meta["config"].path)
if not os.path.exists(environments):
dump_environments(environments)
QCoreApplication.setApplicationName("beat.editor")
QCoreApplication.setOrganizationName("Idiap")
QCoreApplication.setOrganizationDomain("ch.idiap")
......@@ -106,6 +122,7 @@ def editor(ctx, environments):
@editor.command(epilog=START_EPILOG)
@click.pass_context
@refresh_environment_cache_flag
@raise_on_error
def start(ctx):
"""Start the beat editor"""
......@@ -130,6 +147,7 @@ Example:
@click.argument("asset_type")
@click.argument("asset_name")
@click.pass_context
@refresh_environment_cache_flag
@raise_on_error
def edit(ctx, asset_type, asset_name):
"""Edit one specific asset"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment