Skip to content

Commit 564230f

Browse files
committed
feat(cli): ✨ add CLI options for cache configuration (cache-path, cache-max-age)
1 parent b2b47ba commit 564230f

1 file changed

Lines changed: 36 additions & 3 deletions

File tree

rocrate_validator/cli/commands/validate.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from rich.rule import Rule
2626

2727
from rocrate_validator.utils import log as logging
28-
from rocrate_validator import services
28+
from rocrate_validator import constants, services
2929
from rocrate_validator.cli.commands.errors import handle_error
3030
from rocrate_validator.cli.main import cli
3131
from rocrate_validator.cli.ui.text.validate import ValidationCommandView
@@ -205,6 +205,29 @@ def validate_uri(ctx, param, value):
205205
show_default=True,
206206
help="Width of the output line",
207207
)
208+
@click.option(
209+
'--cache-max-age',
210+
type=click.INT,
211+
default=constants.DEFAULT_HTTP_CACHE_MAX_AGE,
212+
show_default=True,
213+
help="Maximum age of the HTTP cache in seconds",
214+
)
215+
@click.option(
216+
'--cache-path',
217+
type=click.Path(),
218+
default=None,
219+
show_default=True,
220+
help="Path to the HTTP cache directory",
221+
)
222+
@click.option(
223+
'-nc',
224+
'--no-cache',
225+
is_flag=True,
226+
help="Disable the HTTP cache",
227+
default=False,
228+
show_default=True,
229+
hidden=True
230+
)
208231
@click.pass_context
209232
def validate(ctx,
210233
profiles_path: Path = DEFAULT_PROFILES_PATH,
@@ -223,7 +246,10 @@ def validate(ctx,
223246
verbose: bool = False,
224247
output_format: str = "text",
225248
output_file: Optional[Path] = None,
226-
output_line_width: Optional[int] = None):
249+
output_line_width: Optional[int] = None,
250+
cache_max_age: int = constants.DEFAULT_HTTP_CACHE_MAX_AGE,
251+
cache_path: Optional[Path] = None,
252+
no_cache: bool = False):
227253
"""
228254
[magenta]rocrate-validator:[/magenta] Validate a RO-Crate against a profile
229255
"""
@@ -247,6 +273,11 @@ def validate(ctx,
247273
logger.debug("fail_fast: %s", fail_fast)
248274
logger.debug("no fail fast: %s", not fail_fast)
249275

276+
# Cache settings
277+
logger.debug("cache_max_age: %s", cache_max_age)
278+
logger.debug("cache_path: %s", os.path.abspath(cache_path) if cache_path else None)
279+
logger.debug("no_cache: %s", no_cache)
280+
250281
if rocrate_uri:
251282
logger.debug("rocrate_path: %s", os.path.abspath(rocrate_uri))
252283

@@ -282,7 +313,9 @@ def validate(ctx,
282313
"rocrate_relative_root_path": relative_root_path,
283314
"abort_on_first": fail_fast,
284315
"skip_checks": skip_checks_list,
285-
"metadata_only": metadata_only
316+
"metadata_only": metadata_only,
317+
"cache_max_age": cache_max_age if not no_cache else -1,
318+
"cache_path": cache_path
286319
}
287320

288321
# Print the application header

0 commit comments

Comments
 (0)