Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion dargs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def check_cli(
func: str,
jdata: list[IO],
strict: bool,
trim_pattern: str = "_*",
allow_ref: bool = False,
**kwargs: Any,
) -> None:
Expand All @@ -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

Expand All @@ -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(
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import io
import json
import subprocess
import sys
import unittest
Expand All @@ -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(
[
Expand Down
Loading