Commit 9eef21fa authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[commands] Refactor all commands to use new AssetInfo data from context

parent f4fc79aa
......@@ -71,13 +71,14 @@ def list_impl(ctx, remote):
$ beat <asset_type> list
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, ctx.meta["asset_type"])
with common.make_webapi(config) as webapi:
return common.display_remote_list(webapi, asset_info.asset_type)
else:
return common.display_local_list(
ctx.meta["config"].path, ctx.meta["asset_type"]
)
return common.display_local_list(config.path, asset_info.asset_type)
@click.argument("names", nargs=-1)
......@@ -90,9 +91,10 @@ def path_impl(ctx, names):
$ beat <asset_type> path xxx
"""
return common.display_local_path(
ctx.meta["config"].path, ctx.meta["asset_type"], names
)
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
return common.display_local_path(config.path, asset_info.asset_type, names)
@click.argument("name", nargs=1)
......@@ -104,9 +106,11 @@ def edit_impl(ctx, name):
Example:
$ beat <asset_type> edit xxx
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
return common.edit_local_file(
ctx.meta["config"].path, ctx.meta["config"].editor, ctx.meta["asset_type"], name
config.path, config.editor, asset_info.asset_type, name
)
......@@ -119,8 +123,10 @@ def check_impl(ctx, names):
Example:
$ beat <asset_type> check xxx
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
return common.check(ctx.meta["config"].path, ctx.meta["asset_type"], names)
return common.check(config.path, asset_info.asset_type, names)
@click.pass_context
......@@ -133,8 +139,10 @@ def status_impl(ctx):
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
with common.make_webapi(config) as webapi:
return common.status(webapi, config.path, ctx.meta["asset_type"])[0]
return common.status(webapi, config.path, asset_info.asset_type)[0]
@click.argument("names", nargs=-1)
......@@ -147,7 +155,10 @@ def create_impl(ctx, names):
$ beat <asset_type> create xxx
"""
return common.create(ctx.meta["config"].path, ctx.meta["asset_type"], names)
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
return common.create(config.path, asset_info.asset_type, names)
@click.argument("name", nargs=1)
......@@ -160,7 +171,10 @@ def version_impl(ctx, name):
$ beat <asset_type> version xxx
"""
return common.new_version(ctx.meta["config"].path, ctx.meta["asset_type"], name)
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
return common.new_version(config.path, asset_info.asset_type, name)
@click.argument("src", nargs=1)
......@@ -174,7 +188,10 @@ def fork_impl(ctx, src, dst):
$ beat <asset_type> fork xxx yyy
"""
return common.fork(ctx.meta["config"].path, ctx.meta["asset_type"], src, dst)
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
return common.fork(config.path, asset_info.asset_type, src, dst)
@click.argument("name", nargs=-1)
......@@ -191,13 +208,13 @@ def rm_impl(ctx, name, remote):
"""
config = ctx.meta["config"]
asset_type = ctx.meta["asset_type"]
asset_info = ctx.meta["asset_info"]
if remote:
with common.make_webapi(config) as webapi:
return common.delete_remote(webapi, asset_type, name)
return common.delete_remote(webapi, asset_info.asset_type, name)
else:
return common.delete_local(config.path, asset_type, name)
return common.delete_local(config.path, asset_info.asset_type, name)
@click.argument("name", nargs=-1)
......@@ -209,8 +226,10 @@ def rm_local_impl(ctx, name):
Example:
$ beat <asset_type> rm xxx
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
return common.delete_local(ctx.meta["config"].path, ctx.meta["asset_type"], name)
return common.delete_local(config.path, asset_info.asset_type, name)
@click.argument("name", nargs=1)
......@@ -224,10 +243,11 @@ def diff_impl(ctx, name):
"""
config = ctx.meta["config"]
asset_info = ctx.meta["asset_info"]
with common.make_webapi(config) as webapi:
return common.diff(
webapi, config.path, ctx.meta["asset_type"], name, ctx.meta["diff_fields"]
webapi, config.path, asset_info.asset_type, name, asset_info.diff_fields
)
......@@ -259,16 +279,17 @@ def command(name):
return copy_func(CMD_TABLE[name])
def initialise_asset_commands(click_cmd_group, cmd_list):
def initialise_asset_commands(click_cmd_group, cmd_list, cmd_cls):
"""Initialize a command group adding all the commands from cmd_list to it
Parameters:
click_cmd_group obj: click command to group
cmd_list list: list of string or tuple of the commands to add
cmd_cls: subclass of click Command to use
"""
for item in cmd_list:
if isinstance(item, tuple):
click_cmd_group.command(name=item[0])(command(item[1]))
click_cmd_group.command(cls=cmd_cls, name=item[0])(command(item[1]))
else:
click_cmd_group.command(name=item)(command(item))
click_cmd_group.command(cls=cmd_cls, name=item)(command(item))
Markdown is supported
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