Commit 8161c5b9 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[commands] Factored all list commands to use common function

parent 536982b5
......@@ -47,6 +47,8 @@ from beat.core import hash
from beat.backend.python.algorithm import Storage as AlgorithmStorage
from . import common
from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
......@@ -327,26 +329,11 @@ def execute_impl(prefix, cache, instructions_file):
@click.pass_context
def algorithms(ctx):
"""Configuration and manipulation of algorithms"""
pass
ctx.meta["asset_type"] = "algorithm"
@algorithms.command()
@click.option(
"--remote", help="Only acts on the remote copy of the algorithm", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the algorithms available on the platform
Example:
$ beat algorithms list --remote
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "algorithm")
else:
return common.display_local_list(ctx.meta["config"].path, "algorithm")
algorithms.command(name="list")(commands.command("list"))
@algorithms.command()
......
......@@ -52,6 +52,8 @@ from beat.core import inputs
from beat.core import utils
from . import common
from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
......@@ -651,28 +653,11 @@ def view_outputs(
@click.pass_context
def databases(ctx):
"""Database commands"""
pass
ctx.meta["asset_type"] = "database"
@databases.command()
@click.option(
"--remote", help="Only acts on the remote copy of the database.", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the databases available on the platform.
To list all existing databases on your local prefix:
$ beat databases list
"""
configuration = ctx.meta["config"]
if remote:
with common.make_webapi(configuration) as webapi:
return common.display_remote_list(webapi, "database")
else:
return common.display_local_list(configuration.path, "database")
databases.command(name="list")(commands.command("list"))
@databases.command()
......
......@@ -43,6 +43,8 @@ from beat.core import dataformat
from . import common
from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
......@@ -134,26 +136,11 @@ def pull_impl(webapi, prefix, names, force, indentation, cache):
@click.pass_context
def dataformats(ctx):
"""Configuration manipulation of data formats"""
pass
ctx.meta["asset_type"] = "dataformat"
@dataformats.command()
@click.option(
"--remote", help="Only acts on the remote copy of the dataformat", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the dataformats available on the platform
Example:
$ beat dataformats list --remote
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "dataformat")
else:
return common.display_local_list(ctx.meta["config"].path, "dataformat")
dataformats.command(name="list")(commands.command("list"))
@dataformats.command()
......
......@@ -51,6 +51,8 @@ from beat.core.hash import toPath
from beat.core.hash import hashDataset
from . import common
from . import commands
from .plotters import plot_impl as plotters_plot
from .plotters import pull_impl as plotters_pull
from .decorators import raise_on_error
......@@ -684,7 +686,11 @@ def plot_impl(
@click.pass_context
def experiments(ctx):
"""experiments commands"""
pass
ctx.meta["asset_type"] = "experiment"
experiments.command(name="list")(commands.command("list"))
@experiments.command()
......@@ -734,27 +740,6 @@ def caches(ctx, name, list, delete, checksum):
return caches_impl(config, name, list, delete, checksum)
@experiments.command()
@click.option(
"--remote", help="Only acts on the remote copy of the list.", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the experiments available on the platform.
To list all existing experiments on your local prefix:
$ beat experiments list
"""
config = ctx.meta.get("config")
if remote:
with common.make_webapi(config) as webapi:
return common.display_remote_list(webapi, "experiment")
else:
return common.display_local_list(config.path, "experiment")
@experiments.command()
@click.argument("names", nargs=-1)
@click.pass_context
......
......@@ -80,6 +80,8 @@ import oset
from beat.core import library
from . import common
from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
......@@ -167,26 +169,11 @@ def pull_impl(webapi, prefix, names, force, indentation, cache):
@click.pass_context
def libraries(ctx):
"""Configuration and manipulation of libraries"""
pass
ctx.meta["asset_type"] = "library"
@libraries.command()
@click.option(
"--remote", help="Only acts on the remote copy of the library", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the libraries available on the platform
Example:
$ beat libraries list --remote
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "library")
else:
return common.display_local_list(ctx.meta["config"].path, "library")
libraries.command(name="list")(commands.command("list"))
@libraries.command()
......
......@@ -38,6 +38,8 @@ import click
import logging
from . import common
from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
......@@ -95,27 +97,11 @@ def pull_impl(webapi, prefix, names, force, indentation, format_cache):
@click.pass_context
def plotterparameters(ctx):
"""Plotterparameters commands"""
pass
ctx.meta["asset_type"] = "plotterparameter"
@plotterparameters.command()
@click.option(
"--remote", help="Only acts on the remote copy of the list.", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the plotterparameters available on the platform.
To list all existing plotterparameters on your local prefix:
$ beat plotterparameters list
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "plotterparameter")
else:
return common.display_local_list(ctx.meta["config"].path, "plotterparameter")
plotterparameters.command(name="list")(commands.command("list"))
@plotterparameters.command()
......
......@@ -48,6 +48,8 @@ from beat.core import plotter
from beat.core import dataformat
from . import common
from . import commands
from .dataformats import pull_impl as dataformats_pull
from .plotterparameters import pull_impl as plotterparameters_pull
from .libraries import pull_impl as libraries_pull
......@@ -311,27 +313,11 @@ def plot_impl(
@click.pass_context
def plotters(ctx):
"""Plotters commands"""
pass
@plotters.command()
@click.option(
"--remote", help="Only acts on the remote copy of the list.", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the plotters available on the platform.
ctx.meta["asset_type"] = "plotter"
To list all existing plotters on your local prefix:
$ beat plotters list
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "plotter")
else:
return common.display_local_list(ctx.meta["config"].path, "plotter")
plotters.command(name="list")(commands.command("list"))
@plotters.command()
......
......@@ -38,6 +38,8 @@ import click
import logging
from . import common
from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
......@@ -52,30 +54,11 @@ logger = logging.getLogger(__name__)
@click.pass_context
def protocoltemplates(ctx):
"""Protocol template commands"""
pass
ctx.meta["asset_type"] = "protocoltemplate"
@protocoltemplates.command()
@click.option(
"--remote",
help="Only acts on the remote copy of the protocoltemplate.",
is_flag=True,
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the databases available on the platform.
To list all existing databases on your local prefix:
$ beat databases list
"""
configuration = ctx.meta["config"]
if remote:
with common.make_webapi(configuration) as webapi:
return common.display_remote_list(webapi, "protocoltemplate")
else:
return common.display_local_list(configuration.path, "protocoltemplate")
protocoltemplates.command(name="list")(commands.command("list"))
@protocoltemplates.command()
......
......@@ -37,6 +37,8 @@
import click
from . import common
from . import commands
from .decorators import raise_on_error
from .click_helper import AliasedGroup
......@@ -45,27 +47,11 @@ from .click_helper import AliasedGroup
@click.pass_context
def toolchains(ctx):
"""toolchains commands"""
pass
ctx.meta["asset_type"] = "toolchain"
@toolchains.command()
@click.option(
"--remote", help="Only acts on the remote copy of the list.", is_flag=True
)
@click.pass_context
@raise_on_error
def list(ctx, remote):
"""Lists all the toolchains available on the platform.
To list all existing toolchains on your local prefix:
$ beat toolchains list
"""
if remote:
with common.make_webapi(ctx.meta["config"]) as webapi:
return common.display_remote_list(webapi, "toolchain")
else:
return common.display_local_list(ctx.meta["config"].path, "toolchain")
toolchains.command(name="list")(commands.command("list"))
@toolchains.command()
......
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