option to filter first level of elements for list
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ Prerequisites:
|
||||
# Arch Linux
|
||||
pacman -S uv just
|
||||
# optional
|
||||
pacman -S just-lsp yamlfmt shellcheck typos
|
||||
pacman -S just-lsp yamlfmt shellcheck typos git-delta
|
||||
```
|
||||
|
||||
The development environment and testing requires multiple specific Python versions; they can be installed with (inside the pulled git project directory):
|
||||
|
||||
@@ -67,7 +67,7 @@ ci-gen: docs
|
||||
uv run --only-group=check ruff format --diff .
|
||||
|
||||
echo "running formatter; yamlfmt (YAML)"
|
||||
uv run yamlfmt -lint -quiet -output_format default -formatter indent=2,indentless_arrays=true,retain_line_breaks_single=true,trim_trailing_whitespace=true .
|
||||
scripts/yamlfmt-diff.sh . | delta
|
||||
|
||||
# fix formatting
|
||||
[group('dev')]
|
||||
@@ -121,7 +121,7 @@ ci-gen: docs
|
||||
[group('dev')]
|
||||
@schema-check:
|
||||
echo "running schema checker (dbyaml config)"
|
||||
uv run scripts/generate_schema.py | diff - src/dbyaml/resources/dbyaml.schema.json
|
||||
uv run scripts/generate_schema.py | diff src/dbyaml/resources/dbyaml.schema.json -
|
||||
|
||||
# generate all docs
|
||||
[group('dev')]
|
||||
|
||||
+17
-4
@@ -163,11 +163,24 @@ else:
|
||||
def main(ctx, filename, config, format_type, quiet, verbose, debug):
|
||||
"""The uncompromising db(yaml) utility."""
|
||||
if ctx.invoked_subcommand is None:
|
||||
ctx.invoke(list)
|
||||
ctx.invoke(lst)
|
||||
|
||||
@main.command
|
||||
@main.command("list")
|
||||
@click.option(
|
||||
"-k",
|
||||
"--keys",
|
||||
is_flag=True,
|
||||
help="List keys.",
|
||||
)
|
||||
@pass_context
|
||||
def list(ctx):
|
||||
def lst(ctx, keys):
|
||||
data = load(ctx.obj["filename"])
|
||||
res = dump(data, format_type=ctx.obj["format_type"])
|
||||
if keys:
|
||||
if isinstance(data, dict):
|
||||
df = list(data.keys())
|
||||
elif isinstance(data, list):
|
||||
df = len(data)
|
||||
else:
|
||||
df = data
|
||||
res = dump(df, format_type=ctx.obj["format_type"])
|
||||
print(res)
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
def load(filename: str) -> list | dict: ...
|
||||
def dump(data: list | dict, format_type: str) -> str: ...
|
||||
def dump(data: object, format_type: str) -> str: ...
|
||||
def run_shebang(script: str) -> None: ...
|
||||
|
||||
@@ -31,7 +31,13 @@
|
||||
"list": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {}
|
||||
"properties": {
|
||||
"keys": {
|
||||
"type": "boolean",
|
||||
"description": "List keys.",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ from dbyaml.cli import pass_context, uses_decorator # ty: ignore[unresolved-imp
|
||||
|
||||
def test_uses_decorator_cli():
|
||||
assert uses_decorator("main", "pass_context", dbyaml.cli.__file__)
|
||||
assert uses_decorator("list", "pass_context", dbyaml.cli.__file__)
|
||||
assert uses_decorator("lst", "pass_context", dbyaml.cli.__file__)
|
||||
|
||||
|
||||
def test_uses_decorator_wo():
|
||||
|
||||
Reference in New Issue
Block a user