Skip to content

Commit

Permalink
fix: arguments can take a colon
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Jun 5, 2024
1 parent cebeff7 commit be58ef4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ ignore = [
"E722",
"RUF001", # Unicode chars
"PLR",
"ISC001", # Conflicts with formatter
]
typing-modules = ["uproot_browser._compat.typing"]
unfixable = [
Expand Down
15 changes: 12 additions & 3 deletions src/uproot_browser/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
from click_default_group import DefaultGroup


def _existing_path_before_colon(_ctx: object, _value: object, path: str) -> str:
prefix, _, _ = path.partition(":")
if not Path(prefix).is_file():
msg = "{prefix!r} must be an exiting path"
raise click.BadParameter(msg)

return path


@click.group(context_settings=CONTEXT_SETTINGS, cls=DefaultGroup, default="browse")
@click.version_option(version=VERSION)
def main() -> None:
Expand All @@ -34,7 +43,7 @@ def main() -> None:


@main.command()
@click.argument("filename", type=click.Path(exists=True))
@click.argument("filename", callback=_existing_path_before_colon)
def tree(filename: str) -> None:
"""
Display a tree.
Expand All @@ -59,7 +68,7 @@ def new_func(*args: Any, **kwargs: Any) -> Any:


@main.command()
@click.argument("filename", type=click.Path(exists=True))
@click.argument("filename", callback=_existing_path_before_colon)
@click.option(
"--iterm", is_flag=True, help="Display an iTerm plot (requires [iterm] extra)."
)
Expand Down Expand Up @@ -100,7 +109,7 @@ def plot(filename: str, iterm: bool) -> None:


@main.command()
@click.argument("filename", type=click.Path(exists=True))
@click.argument("filename", callback=_existing_path_before_colon)
def browse(filename: str) -> None:
"""
Display a TUI.
Expand Down

0 comments on commit be58ef4

Please sign in to comment.