diff --git a/dargs/cli.py b/dargs/cli.py index 3273463..4559b43 100644 --- a/dargs/cli.py +++ b/dargs/cli.py @@ -98,6 +98,7 @@ def check_cli( func: str, jdata: list[IO], strict: bool, + trim_pattern: str = "_*", allow_ref: bool = False, **kwargs: Any, ) -> None: @@ -111,6 +112,8 @@ def check_cli( File object that contains the JSON data strict : bool If True, raise an error if the key is not pre-defined + trim_pattern : str, optional + Glob pattern for keys removed before strict validation. allow_ref : bool, optional If True, allow loading from external files via the ``$ref`` key @@ -133,7 +136,13 @@ def check_cli( arginfo = func_obj() for jj in jdata: data = json.load(jj) - check(arginfo, data, strict=strict, allow_ref=allow_ref) + check( + arginfo, + data, + strict=strict, + trim_pattern=trim_pattern, + allow_ref=allow_ref, + ) def doc_cli( diff --git a/tests/test_cli.py b/tests/test_cli.py index 25ec787..e9755ac 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,5 +1,7 @@ from __future__ import annotations +import io +import json import subprocess import sys import unittest @@ -9,6 +11,18 @@ class TestCli(unittest.TestCase): + def test_check_trim_pattern(self) -> None: + """The CLI forwards its custom trim pattern to the checker.""" + from dargs.cli import check_cli + + data = {"test1": 1, "test2": 2, "dropme": "trimmed"} + check_cli( + func="dargs._test.test_arguments", + jdata=[io.StringIO(json.dumps(data))], + strict=True, + trim_pattern="drop*", + ) + def test_check(self) -> None: subprocess.check_call( [