Take the search and replace program arguments

This commit is contained in:
Sven van Heugten 2026-03-05 17:37:59 +01:00
parent 8b45ac3d87
commit d7637d1cec
No known key found for this signature in database
GPG key ID: D612F88666F4F660

View file

@ -3,11 +3,17 @@
import sys import sys
def should_include_hunk(hunk_text: str) -> bool: def should_include_hunk(hunk_text: str, search: str, replace: str) -> bool:
return True return True
def main() -> None: def main() -> None:
if len(sys.argv) != 3:
raise SystemExit("Usage: mechanicaldiff <search> <replace>")
search = sys.argv[1]
replace = sys.argv[2]
lines = sys.stdin.read().splitlines(keepends=True) lines = sys.stdin.read().splitlines(keepends=True)
preamble_lines = [] preamble_lines = []
sections = [] sections = []
@ -46,7 +52,7 @@ def main() -> None:
kept_hunks = [] kept_hunks = []
for hunk_lines in section["hunks"]: for hunk_lines in section["hunks"]:
hunk_text = "".join(hunk_lines) hunk_text = "".join(hunk_lines)
if should_include_hunk(hunk_text): if should_include_hunk(hunk_text, search, replace):
kept_hunks.append(hunk_lines) kept_hunks.append(hunk_lines)
if not kept_hunks: if not kept_hunks: