Skip to content

Commit

Permalink
validate repo argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rarescosma committed Oct 15, 2024
1 parent 8d2220e commit 73ca8b9
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion octotail/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
""" Options class + some magic so we can define our args in one place only. """

import re
from contextvars import ContextVar
from dataclasses import dataclass
from functools import wraps
Expand All @@ -25,6 +26,13 @@ def _sha_callback(value: str) -> str:
return value


def _repo_callback(value: str | None) -> str | None:
pattern = r"^[a-zA-Z0-9_-]{1,100}/[a-zA-Z0-9_-]{1,100}$"
if value is not None and re.match(pattern, value) is None:
raise BadParameter(f"invalid format for repo: {value}")
return value


@dataclass(frozen=True)
class Opts:
"""
Expand Down Expand Up @@ -77,7 +85,13 @@ class Opts:
] = None
repo: Annotated[
str | None,
Option("-R", "--repo", help=_REPO_HELP, show_default=False),
Option(
"-R",
"--repo",
help=_REPO_HELP,
show_default=False,
callback=_repo_callback,
),
] = None
headless: Annotated[bool, Option(envvar="_HEADLESS")] = True
port: Annotated[
Expand Down

0 comments on commit 73ca8b9

Please sign in to comment.