Add 1_write_events/src/write_events/cli.py
This commit is contained in:
parent
73bbd606aa
commit
90d3f7536f
1 changed files with 66 additions and 0 deletions
66
1_write_events/src/write_events/cli.py
Normal file
66
1_write_events/src/write_events/cli.py
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
from write_events import core
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""CLI-Einstiegspunkt für Write-Event-Aufzeichnung."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description=(
|
||||||
|
"Erfasst Write-Events für Systemvariablen mit Metadaten und schreibt sie in ein JSON-Log."
|
||||||
|
)
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--field-tag",
|
||||||
|
required=True,
|
||||||
|
help="Tag des zu protokollierenden Feldes (z. B. base_raw_write).",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--new-value-hash",
|
||||||
|
required=True,
|
||||||
|
help="Hash-Wert des neuen Inhalts.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--corr-id",
|
||||||
|
required=True,
|
||||||
|
help="Korrelations-ID zur Gruppierung von Events.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=False,
|
||||||
|
default="output/write_events.json",
|
||||||
|
help="Pfad zur Ausgabedatei für Write-Event-Logs (Standard: output/write_events.json).",
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Validation of arguments
|
||||||
|
if not args.field_tag.strip():
|
||||||
|
print("Fehler: --field-tag darf nicht leer sein.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
if not args.new_value_hash.strip():
|
||||||
|
print("Fehler: --new-value-hash darf nicht leer sein.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
if not args.corr_id.strip():
|
||||||
|
print("Fehler: --corr-id darf nicht leer sein.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Ensure output directory exists
|
||||||
|
output_path = Path(args.output).expanduser().resolve()
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
core.record_write_event(
|
||||||
|
field_tag=args.field_tag,
|
||||||
|
new_value_hash=args.new_value_hash,
|
||||||
|
corr_id=args.corr_id,
|
||||||
|
)
|
||||||
|
print(f"Write-Event für '{args.field_tag}' erfolgreich protokolliert.")
|
||||||
|
except Exception as exc: # noqa: BLE001
|
||||||
|
print(f"Fehler beim Aufzeichnen des Write-Events: {exc}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue