Skip to content

Commit

Permalink
Directly parse URL in the CLI command (#21)
Browse files Browse the repository at this point in the history
Cleans up the implementation of URL handling in the configuration dump command.
  • Loading branch information
Callum027 authored Sep 9, 2023
1 parent 32e5f8e commit 3e5a98f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions buildarr_prowlarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import functools

from getpass import getpass
from typing import TYPE_CHECKING
from urllib.parse import urlparse

import click
Expand All @@ -30,6 +31,9 @@
from .manager import ProwlarrManager
from .secrets import ProwlarrSecrets

if TYPE_CHECKING:
from urllib.parse import ParseResult as Url

HOSTNAME_PORT_TUPLE_LENGTH = 2


Expand All @@ -48,7 +52,7 @@ def prowlarr():
"The configuration is dumped to standard output in Buildarr-compatible YAML format."
),
)
@click.argument("url", type=click.STRING)
@click.argument("url", type=urlparse)
@click.option(
"-k",
"--api-key",
Expand All @@ -57,15 +61,14 @@ def prowlarr():
default=functools.partial(getpass, "Prowlarr instance API key: "),
help="API key of the Prowlarr instance. The user will be prompted if undefined.",
)
def dump_config(url: str, api_key: str) -> int:
def dump_config(url: Url, api_key: str) -> int:
"""
Dump configuration from a remote Prowlarr instance.
The configuration is dumped to standard output in Buildarr-compatible YAML format.
"""

url_obj = urlparse(url)
protocol = url_obj.scheme
hostname_port = url_obj.netloc.split(":", 1)
protocol = url.scheme
hostname_port = url.netloc.split(":", 1)
hostname = hostname_port[0]
port = (
int(hostname_port[1])
Expand Down

0 comments on commit 3e5a98f

Please sign in to comment.