Commit 6717ded8 authored by Samuel GAIST's avatar Samuel GAIST

[commands] Factored all diff commands to use common function

parent 270432b5
......@@ -331,6 +331,7 @@ def algorithms(ctx):
"""Configuration and manipulation of algorithms"""
ctx.meta["asset_type"] = "algorithm"
ctx.meta["diff_fields"] = ["declaration", "code", "description"]
algorithms.command(name="list")(commands.command("list"))
......@@ -342,6 +343,7 @@ algorithms.command(name="create")(commands.command("create"))
algorithms.command(name="version")(commands.command("version"))
algorithms.command(name="fork")(commands.command("fork"))
algorithms.command(name="rm")(commands.command("rm"))
algorithms.command(name="diff")(commands.command("diff"))
@algorithms.command()
......@@ -393,26 +395,6 @@ def push(ctx, name, force, dry_run):
)
@algorithms.command()
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def diff(ctx, name):
"""Shows changes between the local algorithm and the remote version
Example:
$ beat algorithms diff xxx
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.diff(
webapi,
ctx.meta["config"].path,
"algorithm",
name,
["declaration", "code", "description"],
)
@algorithms.command()
@click.argument("instructions", nargs=1)
@click.option(
......
......@@ -203,14 +203,32 @@ def rm_impl(ctx, name, remote):
@click.argument("name", nargs=-1)
@click.pass_context
@raise_on_error
def rm_local_impl(ctx, name, remote):
def rm_local_impl(ctx, name):
"""Deletes a local asset
Example:
$ beat <asset_type> rm xxx
"""
return common.delete_local(ctx.meta["config"], ctx.meta["asset_type"], name)
return common.delete_local(ctx.meta["config"].path, ctx.meta["asset_type"], name)
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def diff_impl(ctx, name):
"""Shows changes between the local dataformat and the remote version
Example:
$ beat toolchains diff xxx
"""
config = ctx.meta["config"]
with common.make_webapi(config) as webapi:
return common.diff(
webapi, config.path, ctx.meta["asset_type"], name, ctx.meta["diff_fields"]
)
CMD_TABLE = {
......@@ -224,6 +242,7 @@ CMD_TABLE = {
"fork": fork_impl,
"rm": rm_impl,
"rm_local": rm_local_impl,
"diff": diff_impl,
}
......
......@@ -655,6 +655,7 @@ def databases(ctx):
"""Database commands"""
ctx.meta["asset_type"] = "database"
ctx.meta["diff_fields"] = ["declaration", "code", "description"]
databases.command(name="list")(commands.command("list"))
......@@ -665,6 +666,7 @@ databases.command(name="status")(commands.command("status"))
databases.command(name="create")(commands.command("create"))
databases.command(name="version")(commands.command("version"))
databases.command(name="rm")(commands.command("rm_local"))
databases.command(name="diff")(commands.command("diff"))
@databases.command()
......@@ -719,31 +721,6 @@ def push(ctx, db_names, force, dry_run):
)
@databases.command()
@click.argument("db_names", nargs=-1)
@click.pass_context
@raise_on_error
def diff(ctx, db_names):
"""Shows changes between the local database and the remote version.
$ beat databases diff [<name>]...
<name>:
Database name formatted as "<database>/<version>"
"""
configuration = ctx.meta["config"]
if len(db_names) < 1:
raise click.ClickException("Requires at least one database name")
with common.make_webapi(configuration) as webapi:
return common.diff(
webapi,
configuration.path,
"database",
db_names[0],
["declaration", "code", "description"],
)
@databases.command()
@click.argument("db_names", nargs=-1)
@click.option(
......
......@@ -138,6 +138,7 @@ def dataformats(ctx):
"""Configuration manipulation of data formats"""
ctx.meta["asset_type"] = "dataformat"
ctx.meta["diff_fields"] = ["declaration", "description"]
dataformats.command(name="list")(commands.command("list"))
......@@ -149,6 +150,7 @@ dataformats.command(name="create")(commands.command("create"))
dataformats.command(name="version")(commands.command("version"))
dataformats.command(name="fork")(commands.command("fork"))
dataformats.command(name="rm")(commands.command("rm"))
dataformats.command(name="diff")(commands.command("diff"))
@dataformats.command()
......@@ -201,23 +203,3 @@ def push(ctx, name, force, dry_run):
dry_run,
0,
)
@dataformats.command()
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def diff(ctx, name):
"""Shows changes between the local dataformat and the remote version
Example:
$ beat dataformats diff xxx
"""
with common.make_webapi(ctx.meta.get("config")) as webapi:
return common.diff(
webapi,
ctx.meta.get("config").path,
"dataformat",
name,
["declaration", "description"],
)
......@@ -688,6 +688,7 @@ def experiments(ctx):
"""experiments commands"""
ctx.meta["asset_type"] = "experiment"
ctx.meta["diff_fields"] = ["declaration", "description"]
experiments.command(name="list")(commands.command("list"))
......@@ -697,6 +698,7 @@ experiments.command(name="check")(commands.command("check"))
experiments.command(name="status")(commands.command("status"))
experiments.command(name="fork")(commands.command("fork"))
experiments.command(name="rm")(commands.command("rm"))
experiments.command(name="diff")(commands.command("diff"))
@experiments.command()
......@@ -796,23 +798,6 @@ def push(ctx, names, force, dry_run):
)
@experiments.command()
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def diff(ctx, name):
"""Shows changes between the local dataformat and the remote version.
Example:
$ beat experiments diff xxx
"""
config = ctx.meta.get("config")
with common.make_webapi(config) as webapi:
return common.diff(
webapi, config.path, "experiment", name, ["declaration", "description"]
)
@experiments.command()
@click.argument("names", nargs=-1)
@click.option(
......
......@@ -171,6 +171,7 @@ def libraries(ctx):
"""Configuration and manipulation of libraries"""
ctx.meta["asset_type"] = "library"
ctx.meta["diff_fields"] = ["declaration", "code", "description"]
libraries.command(name="list")(commands.command("list"))
......@@ -182,6 +183,7 @@ libraries.command(name="create")(commands.command("create"))
libraries.command(name="version")(commands.command("version"))
libraries.command(name="fork")(commands.command("fork"))
libraries.command(name="rm")(commands.command("rm"))
libraries.command(name="diff")(commands.command("diff"))
@libraries.command()
......@@ -231,23 +233,3 @@ def push(ctx, names, force, dry_run):
dry_run,
0,
)
@libraries.command()
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def diff(ctx, name):
"""Shows changes between the local library and the remote version
Example:
$ beat libraries diff xxx
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.diff(
webapi,
ctx.meta["config"].path,
"library",
name,
["declaration", "code", "description"],
)
......@@ -49,6 +49,7 @@ def toolchains(ctx):
"""toolchains commands"""
ctx.meta["asset_type"] = "toolchain"
ctx.meta["diff_fields"] = ["declaration", "description"]
toolchains.command(name="list")(commands.command("list"))
......@@ -60,6 +61,7 @@ toolchains.command(name="create")(commands.command("create"))
toolchains.command(name="version")(commands.command("version"))
toolchains.command(name="fork")(commands.command("fork"))
toolchains.command(name="rm")(commands.command("rm"))
toolchains.command(name="diff")(commands.command("diff"))
@toolchains.command()
......@@ -119,26 +121,6 @@ def push(ctx, names, force, dry_run):
)
@toolchains.command()
@click.argument("name", nargs=1)
@click.pass_context
@raise_on_error
def diff(ctx, name):
"""Shows changes between the local dataformat and the remote version
Example:
$ beat toolchains diff xxx
"""
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.diff(
webapi,
ctx.meta["config"].path,
"toolchain",
name,
["declaration", "description"],
)
@toolchains.command()
@click.argument("names", nargs=-1)
@click.option(
......
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