37 lines
758 B
Python
37 lines
758 B
Python
#!/usr/bin/env -S uv run --script
|
|
# /// script
|
|
# requires-python = ">=3.11"
|
|
# dependencies = [
|
|
# "click",
|
|
# ]
|
|
# ///
|
|
|
|
import click
|
|
import json
|
|
import sys
|
|
|
|
def remove_key(obj: dict, key: str, value: object) -> dict:
|
|
obj[key] = value
|
|
return obj
|
|
|
|
|
|
@click.command()
|
|
@click.option(
|
|
"--delete-key",
|
|
multiple=True,
|
|
help="Remove a key-value from a record"
|
|
)
|
|
def main(delete_key: tuple) -> None:
|
|
"""Read a record from stdin and do operations on it before dumping it to stdout"""
|
|
|
|
for line in sys.stdin:
|
|
line = line.strip()
|
|
if not line:
|
|
continue
|
|
obj = json.loads(line)
|
|
for key in delete_key:
|
|
obj.pop(key, None)
|
|
print(json.dumps(obj))
|
|
|
|
if __name__ == "__main__":
|
|
main()
|