Skip to content

Bulk asynchronous downloader for multiple file hosts

fix: parsing of CLI bool flags (#2029)

NTFSvolume65f2f09e722e
diff --git a/cyberdrop_dl/__main__.py b/cyberdrop_dl/__main__.py
index 70b9c858d..daec1c871 100644
--- a/cyberdrop_dl/__main__.py
+++ b/cyberdrop_dl/__main__.py
@@ -2,6 +2,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING
+from cyberdrop_dl.config import parse_tokens
+
if TYPE_CHECKING:
from collections.abc import Sequence
@@ -37,7 +39,7 @@ def run_cdl(args: Sequence[str] | None = None) -> int:
from cyberdrop_dl.exceptions import CDLConfigRuntimeErrorsGroup, DatabaseError
try:
- app(args)
+ app(parse_tokens(args))
except (ValidationError, DatabaseError) as exc:
tb = tracebacks.from_exception(exc.with_traceback(None))
app.console.print(_error_panel(tb))
diff --git a/cyberdrop_dl/config/__init__.py b/cyberdrop_dl/config/__init__.py
index 780d51bb0..3825ebef9 100644
--- a/cyberdrop_dl/config/__init__.py
+++ b/cyberdrop_dl/config/__init__.py
@@ -10,6 +10,7 @@ from cyclopts.bind import normalize_tokens
from pydantic import AfterValidator, BaseModel, Field, NonNegativeInt, PositiveInt
from cyberdrop_dl.config.appdata import AppData
+from cyberdrop_dl.constants import DEFAULT_PARAMETER
from cyberdrop_dl.exceptions import CDLConfigRuntimeErrorsGroup, InvalidYamlError
from cyberdrop_dl.models import ConfigModel, merge_models
from cyberdrop_dl.models.types import ByteSizeSerilized # noqa: TC001
@@ -19,7 +20,7 @@ from cyberdrop_dl.utils import cleanup
from .auth import Authentication, Notifications
from .crawlers import Crawlers
from .filters import Filters
-from .settings import Downloads, Hashing, Jdownloader, Logs, MaxChildren, Network, Sort, SubFolders, UIOptions
+from .settings import ALIASES, Downloads, Hashing, Jdownloader, Logs, MaxChildren, Network, Sort, SubFolders, UIOptions
if TYPE_CHECKING:
from collections.abc import Iterable
@@ -146,9 +147,9 @@ class Config(ConfigModel, title="cyberdrop-dl config"):
def parse_args(tokens: str | Iterable[str]) -> Config:
global _app # noqa: PLW0603
if _app is None:
- _app = App(print_error=False, exit_on_error=False)
+ _app = App(print_error=False, exit_on_error=False, default_parameter=DEFAULT_PARAMETER)
_ = _app.command(name="coerce")(_coerce)
- fn, bound, *_ = _app.parse_args(["coerce", *normalize_tokens(tokens)])
+ fn, bound, *_ = _app.parse_args(["coerce", *parse_tokens(tokens)])
assert fn is _coerce
return _coerce(*bound.args, **bound.kwargs)
@@ -173,6 +174,10 @@ class Config(ConfigModel, title="cyberdrop-dl config"):
return me
+def parse_tokens(tokens: Iterable[str] | str | None) -> list[str]:
+ return [ALIASES.get(token, token) for token in normalize_tokens(tokens)]
+
+
def _resolve_paths(model: BaseModel) -> None:
for field_name, field_value in model:
if isinstance(field_value, Path):
diff --git a/cyberdrop_dl/config/settings.py b/cyberdrop_dl/config/settings.py
index b828544f0..be557e415 100644
--- a/cyberdrop_dl/config/settings.py
+++ b/cyberdrop_dl/config/settings.py
@@ -24,6 +24,15 @@ from cyberdrop_dl.models.types import (
)
from cyberdrop_dl.models.validators import strings
+ALIASES: dict[str, str] = {}
+
+
+def _alias(name: str, *extras: str, flag: str = "enabled") -> Parameter:
+ aliases = (f"--{name}", f"--{name}.{flag}")
+ negative_aliases = (f"--{name}.no-{flag}", f"--no-{name}")
+ ALIASES.update([aliases, negative_aliases])
+ return Parameter(alias=aliases + extras, negative_alias=negative_aliases)
+
class _SubFoldersInclude(ConfigModel):
album_id: bool = False
@@ -39,12 +48,12 @@ class _SeparatePosts(ConfigModel):
Parameter(name="separate-posts.format"),
] = "{default}"
- enabled: Annotated[bool, Parameter(name="separate-posts")] = False
+ enabled: Annotated[bool, _alias("separate-posts")] = False
"Create new subfolders for every post on a site"
class SubFolders(ConfigGroup, name=None):
- create: Annotated[bool, Parameter(name="--subfolders")] = True
+ create: Annotated[bool, _alias("subfolders", flag="create")] = True
"Enable/disable the createtion of nested sub-folders"
include: _SubFoldersInclude = Field(default_factory=_SubFoldersInclude)
@@ -149,7 +158,7 @@ class Logs(ConfigGroup, name=None): # noqa: PLW1641
class Jdownloader(ConfigGroup, name=None):
- enabled: Annotated[bool, Parameter(name="--jdownloader")] = False
+ enabled: Annotated[bool, _alias("jdownloader")] = False
"Send unsupported URLs to Jdownloader"
autostart: bool = False
@@ -212,7 +221,7 @@ class SortFormats(ConfigModel):
class Sort(ConfigGroup, name=None):
- enabled: Annotated[bool, Parameter(name="--sort")] = False
+ enabled: Annotated[bool, _alias("sort")] = False
"Enable/Disable file sorting at the end of a run"
input_folder: FalsyAsNone[Path] = None
@@ -229,7 +238,7 @@ class Sort(ConfigGroup, name=None):
class Dedupe(ConfigModel):
- enabled: Annotated[bool, Parameter(name="--hashing.dedupe", alias="--auto-dedupe")] = True
+ enabled: Annotated[bool, _alias("dedupe", "--auto-dedupe")] = True
"Auto delete duplicate downloads by hash"
use_trash_bin: bool = True
diff --git a/pyproject.toml b/pyproject.toml
index dde23fa79..567df4c25 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -26,7 +26,7 @@ dependencies = [
"brotli >=1.2.0; implementation_name=='cpython' and sys_platform!='ios'",
"certifi >=2026.6.17",
"curl-cffi >=0.15; implementation_name == 'cpython' ",
- "cyclopts==4.20.0",
+ "cyclopts==4.22.1",
"idna>=3.18",
"imagesize >=2.0.0",
"inquirer>=3.4.1",
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 9d40c5f42..2ce6ea279 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -8,6 +8,7 @@ from cyberdrop_dl import __version__
from cyberdrop_dl.__main__ import run_cdl
from cyberdrop_dl.commands import CLIarguments
from cyberdrop_dl.commands.report import generate_report
+from cyberdrop_dl.config import Config
app = App(result_action="return_value", exit_on_error=False, suppress_keyboard_interrupt=False)
@@ -60,3 +61,16 @@ def test_cli_args_parsing(tmp_cwd: Path) -> None:
assert cli.config_file == tmp_cwd / config_yaml
assert cli.database_file is None
assert cli.cache_file is None
+
+
+def test_custom_bool_parsing() -> None:
+ config = Config.parse_args("--jdownloader")
+ assert config.jdownloader.enabled
+ config = Config.parse_args("--no-jdownloader")
+ assert not config.jdownloader.enabled
+ config = Config.parse_args("--jdownloader.no-enabled")
+ assert not config.jdownloader.enabled
+ config = Config.parse_args("--sort")
+ assert config.sort.enabled
+ config = Config.parse_args("--no-sort")
+ assert not config.sort.enabled
diff --git a/uv.lock b/uv.lock
index 368ce21f1..7a41286c6 100644
--- a/uv.lock
+++ b/uv.lock
@@ -675,7 +675,7 @@ requires-dist = [
{ name = "certifi", specifier = ">=2026.6.17" },
{ name = "click", marker = "extra == 'apprise'", specifier = ">=8.4.1" },
{ name = "curl-cffi", marker = "implementation_name == 'cpython'", specifier = ">=0.15" },
- { name = "cyclopts", specifier = "==4.20.0" },
+ { name = "cyclopts", specifier = "==4.22.1" },
{ name = "idna", specifier = ">=3.18" },
{ name = "imagesize", specifier = ">=2.0.0" },
{ name = "inquirer", specifier = ">=3.4.1" },
@@ -711,7 +711,7 @@ dev = [
[[package]]
name = "cyclopts"
-version = "4.20.0"
+version = "4.22.1"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "attrs" },
@@ -719,9 +719,9 @@ dependencies = [
{ name = "rich" },
{ name = "rich-rst" },
]
-sdist = { url = "https://files.pythonhosted.org/packages/74/89/f4c775c651d91f9cd8149f70baec94c902a34e5f17a7a67881881bcfb244/cyclopts-4.20.0.tar.gz", hash = "sha256:1d819de2b12dc6b1c9f17ce0f4937d82922c0b83ac846eb4b3289c9c9f321c9f", size = 190236, upload-time = "2026-06-29T15:04:42.253Z" }
+sdist = { url = "https://files.pythonhosted.org/packages/3d/47/32d992e829f63aedea5b93360db23c8882c9bbbde094bcf0fff899ea8a3b/cyclopts-4.22.1.tar.gz", hash = "sha256:49cd3779da7113a96ac5c23b151aa61ac9ae1b4b1fe813594d207ca843c97892", size = 193551, upload-time = "2026-07-20T17:38:59.38Z" }
wheels = [
- { url = "https://files.pythonhosted.org/packages/dd/d4/7243bc65d33c5ff5150569c42c8c1154aadae20b25638afe35f7f568489c/cyclopts-4.20.0-py3-none-any.whl", hash = "sha256:0b4337e9c11303d86b33d3f37c629dc01638f84591681e0e5611286bdd507646", size = 229383, upload-time = "2026-06-29T15:04:40.621Z" },
+ { url = "https://files.pythonhosted.org/packages/9a/89/f2710638cd2f824cb976777e63ef6ed1e83fc56888cf5c9f5a053490b7be/cyclopts-4.22.1-py3-none-any.whl", hash = "sha256:9b614e231075aee9849c0bfd78f7611ab7adf417f16af5b9e42b9ed6e18c17d1", size = 232953, upload-time = "2026-07-20T17:38:58.078Z" },
]
[[package]]