Skip to content

Bulk asynchronous downloader for multiple file hosts

feat: add cache command

NTFSvolumec7e96b26d603
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 21fd78cf0..b0961b489 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -36,10 +36,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New `--hashes` option to control which hashes CDL computes for new downloads
- New `--database-file` option
- New `--cache-file` option
-- New `download` subcommand (replaces the `--download` argument)
-- New `config` subcommand
-- New `hash` subcommand
-- New `report` subcommand
+- New `download` CLI command (replaces the `--download` argument)
+- New `config` CLI command
+- New `cache` CLI command
+- New `hash` CLI command
+- New `report` CLI command
### Changed
diff --git a/cyberdrop_dl/cli.py b/cyberdrop_dl/cli.py
index fbf6a1692..bcfb42ced 100644
--- a/cyberdrop_dl/cli.py
+++ b/cyberdrop_dl/cli.py
@@ -8,6 +8,7 @@ from cyclopts.help import DefaultFormatter
from cyberdrop_dl import __version__
from cyberdrop_dl.commands import CLIarguments
+from cyberdrop_dl.commands.cache import app as cache_app
from cyberdrop_dl.commands.cleanup import app as cleanup_app
from cyberdrop_dl.commands.config import app as config_app
from cyberdrop_dl.commands.database import app as database_app
@@ -65,7 +66,7 @@ def report() -> None:
app.console.print(generate_report())
-for cmd in download, database_app, cleanup_app, config_app:
+for cmd in download, database_app, cleanup_app, config_app, cache_app:
app.command(cmd)
diff --git a/cyberdrop_dl/commands/cache.py b/cyberdrop_dl/commands/cache.py
new file mode 100644
index 000000000..657b2c11a
--- /dev/null
+++ b/cyberdrop_dl/commands/cache.py
@@ -0,0 +1,31 @@
+import logging
+
+from cyclopts import App
+
+from cyberdrop_dl.commands import CLIarguments
+from cyberdrop_dl.config.appdata import AppData
+
+app = App(name="cache", help="Cache operations")
+logger = logging.getLogger(__name__)
+
+
+def file(*, cli: CLIarguments | None = None) -> None:
+ "Show path to the cache file"
+ file = cli.cache_file if cli else None
+ file = file or AppData.default().cache_file
+ app.console.print(file)
+
+
+def clear(*, cli: CLIarguments | None = None) -> None:
+ "Delete the cache file"
+
+ file = cli.cache_file if cli else None
+ file = file or AppData.default().cache_file
+ try:
+ file.unlink()
+ except FileNotFoundError:
+ logger.info("Cache file does not exists. Nothing to do")
+ else:
+ logger.info("Cache file at '%s' deleted", file)
diff --git a/cyberdrop_dl/commands/config.py b/cyberdrop_dl/commands/config.py
index edc3afdb2..fb4791258 100644
--- a/cyberdrop_dl/commands/config.py
+++ b/cyberdrop_dl/commands/config.py
@@ -14,7 +14,9 @@ logger = logging.getLogger(__name__)
@app.command()
def file(*, cli: CLIarguments | None = None) -> None:
"Show path to the config file"
- app.console.print(cli.config_file if cli else AppData.default().config_file)
+ file = cli.config_file if cli else None
+ file = file or AppData.default().config_file
+ app.console.print(file)
@app.command()