diff --git a/src/mdio/__main__.py b/src/mdio/__main__.py index 10e3ae3e..4223f383 100644 --- a/src/mdio/__main__.py +++ b/src/mdio/__main__.py @@ -11,6 +11,7 @@ import mdio +from mdio.commands.utility import copy, info plugin_folder = os.path.join(os.path.dirname(__file__), "commands") @@ -40,11 +41,18 @@ class MyCLI(click.MultiCommand): http://lybniz2.sourceforge.net/safeeval.html """ + _command_mapping = { + "copy": copy, + "info": info, + } + + protected_files = ["__init__.py", "utility.py"] + def list_commands(self, ctx: click.Context) -> list[str]: """List commands available under `commands` module.""" - rv = [] + rv = list(self._command_mapping.keys()) for filename in os.listdir(plugin_folder): - if filename.endswith(".py") and filename != "__init__.py": + if filename.endswith(".py") and filename not in self.protected_files: rv.append(filename[:-3]) rv.sort() @@ -61,6 +69,8 @@ def get_command(self, ctx: click.Context, name: str) -> dict[Callable]: } local_ns = {} + if name in self._command_mapping.keys(): + return self._command_mapping[name] fn = os.path.join(plugin_folder, name + ".py") with open(fn) as f: code = compile(f.read(), fn, "exec") diff --git a/src/mdio/commands/utility.py b/src/mdio/commands/utility.py index 9b0d3d78..595a2d1a 100644 --- a/src/mdio/commands/utility.py +++ b/src/mdio/commands/utility.py @@ -1,11 +1,11 @@ """Dataset CLI Plugin.""" - try: import click import click_params import mdio + from typing import Optional except SystemError: pass @@ -21,7 +21,7 @@ def cli(): click.echo("MDIO CLI utilities") -@cli.command(name="copy") +@click.command(name="copy") @click.option( "-i", "--input-mdio-path", @@ -76,7 +76,7 @@ def copy( output_mdio_path: str, includes: str = "", excludes: str = "", - storage_options: dict | None = None, + storage_options: Optional[dict] = None, overwrite: bool = False, ): """Copy MDIO to MDIO. @@ -111,7 +111,7 @@ def copy( ) -@cli.command(name="info") +@click.command(name="info") @click.option( "-i", "--input-mdio-file",