Files
claude-config/bin/loop_claude/claude_code/trust.py
T

27 lines
846 B
Python

import json
import sys
from loop_claude.claude_code.formats import mark_trusted
from loop_claude.file_writes import replace_json
from loop_claude.outcome import Failure
def trust(config, roots):
try:
with open(config, encoding="utf-8") as handle:
data = json.load(handle)
except (OSError, ValueError) as failure:
print(f"could not read {config}: {getattr(failure, 'strerror', failure)}", file=sys.stderr)
return
marked = mark_trusted(data, roots)
if isinstance(marked, Failure):
print(f"could not read {config}: {marked.reason}", file=sys.stderr)
return
updated, untrusted = marked
if not untrusted:
return
if failure := replace_json(config, updated, indent=2):
print(f"could not write {config}: {failure.reason}", file=sys.stderr)
return
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)