all repos — fae @ 9f23c088dce9a005ba5f2c117b11ecece0923396

A minuscule find and edit utility.

Added --help and --version.
h3rald h3rald@h3rald.com
Sun, 24 May 2015 12:44:20 +0200
commit

9f23c088dce9a005ba5f2c117b11ecece0923396

parent

7fd37a67698bbc116d025a5e1da491680737e744

1 files changed, 30 insertions(+), 1 deletions(-)

jump to
M far.nimfar.nim

@@ -18,6 +18,28 @@ test: bool

system.addQuitProc(resetAttributes) +const version = "1.0.0" + +const usage = """FAR v""" & version & """ - Find & Replace Utility + (c) 2015 Fabio Cevasco + + Usage: + far <pattern> [<replacement>] [option1 option2 ...] + + Where: + <pattern> A regular expression to search for + <replacement> An optional replacement string + + Options: + -a, --apply Substitute all occurrences of <pattern> with <replacement> in all files + without asking for confirmation. + -d, --directory Search in the specified directory (default: .) + -f, --filter Specify a regular expression to filter file paths. + -h, --help Display this message. + -r, --recursive Search directories recursively. + -t, --test Do not perform substitutions, just print results. + -v, --version Display the program version. +""" proc matchBounds(str, regex: string, start = 0): StringBounds = var c = cast[ptr array[0..9,Capture]](alloc0(sizeof(array[0..9, Capture])))

@@ -128,13 +150,20 @@ of "apply", "a":

options.apply = true of "test", "t": options.test = true + of "help", "h": + echo usage + quit(0) + of "version", "v": + echo version + quit(0) else: discard else: discard if options.regex == nil: - quit("No regex specified.", 2) + echo usage + quit(0) var scan: iterator(dir: string): string {.closure.}