Skip to content

Commit

Permalink
Move utility commands to root level.
Browse files Browse the repository at this point in the history
  • Loading branch information
markspec authored and tasansal committed Aug 25, 2023
1 parent d8331e2 commit 638d387
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions src/mdio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import mdio

from mdio.commands.utility import copy, info

plugin_folder = os.path.join(os.path.dirname(__file__), "commands")

Expand Down Expand Up @@ -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()

Expand All @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions src/mdio/commands/utility.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Dataset CLI Plugin."""


try:
import click
import click_params

import mdio
from typing import Optional
except SystemError:
pass

Expand All @@ -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",
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -111,7 +111,7 @@ def copy(
)


@cli.command(name="info")
@click.command(name="info")
@click.option(
"-i",
"--input-mdio-file",
Expand Down

0 comments on commit 638d387

Please sign in to comment.