Implemented --test flag.
h3rald h3rald@h3rald.com
Sun, 24 May 2015 12:34:36 +0200
1 files changed,
5 insertions(+),
2 deletions(-)
jump to
M
far.nim
→
far.nim
@@ -14,6 +14,7 @@ filter: string
substitute: string directory: string apply: bool + test: bool system.addQuitProc(resetAttributes)@@ -104,7 +105,7 @@ return confirm(msg)
## Processing Options -var options = FarOptions(regex: nil, recursive: false, filter: nil, substitute: nil, directory: ".", apply: false) +var options = FarOptions(regex: nil, recursive: false, filter: nil, substitute: nil, directory: ".", apply: false, test: false) for kind, key, val in getOpt(): case kind:@@ -125,6 +126,8 @@ of "directory", "d":
options.directory = val of "apply", "a": options.apply = true + of "test", "t": + options.test = true else: discard else:@@ -171,7 +174,7 @@ displayMatch(contents, matchstart, matchend, fgRed)
var replacement = contents.replace(options.regex, options.substitute, matchstart) var new_offset = options.substitute.len-(matchend-matchstart+1) displayMatch(replacement, matchstart, matchend+new_offset, fgYellow) - if options.apply or confirm("Confirm replacement? [Y/n] "): + if (not options.test) and (options.apply or confirm("Confirm replacement? [Y/n] ")): f.writefile(replacement) contents = f.readFile() offset = offset + new_offset