Take the search and replace program arguments
This commit is contained in:
parent
8b45ac3d87
commit
d7637d1cec
1 changed files with 8 additions and 2 deletions
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue