Skip to content

Commit 44e754f

Browse files
authored
fix: arguments can take a colon (#170)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent cebeff7 commit 44e754f

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ ignore = [
158158
"E722",
159159
"RUF001", # Unicode chars
160160
"PLR",
161+
"ISC001", # Conflicts with formatter
161162
]
162163
typing-modules = ["uproot_browser._compat.typing"]
163164
unfixable = [

src/uproot_browser/__main__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
from click_default_group import DefaultGroup
2626

2727

28+
def _existing_path_before_colon(_ctx: object, _value: object, path: str) -> str:
29+
prefix, _, _ = path.partition(":")
30+
if not Path(prefix).is_file():
31+
msg = "{prefix!r} must be an exiting path"
32+
raise click.BadParameter(msg)
33+
34+
return path
35+
36+
2837
@click.group(context_settings=CONTEXT_SETTINGS, cls=DefaultGroup, default="browse")
2938
@click.version_option(version=VERSION)
3039
def main() -> None:
@@ -34,7 +43,7 @@ def main() -> None:
3443

3544

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

6069

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

101110

102111
@main.command()
103-
@click.argument("filename", type=click.Path(exists=True))
112+
@click.argument("filename", callback=_existing_path_before_colon)
104113
def browse(filename: str) -> None:
105114
"""
106115
Display a TUI.

0 commit comments

Comments
 (0)