diff --git a/examples/simple-grep.rn b/examples/simple-grep.rn index 9c8bc41..8772f8c 100644 --- a/examples/simple-grep.rn +++ b/examples/simple-grep.rn @@ -1,40 +1,40 @@ -import Argparser +import argparser fun main() { - parser = Argparser.Argparser() + var parser = argparser.Argparser() parser.add_flag("--help", "-h", "Show this help text and exit") parser.add_pos_opt("query", "String to query", required=true) parser.add_pos_opt("file", "File to query string in", required=true) parser.add_flag("--line-numbers", "-n", "Show line numbers") parser.add_named("--max-lines", "Maximum amount of lines to show", conversor=int) - args = parser.parse(argv[:]) + var args = parser.parse(argv[:]) if args["--help"] { print(parser.usage(argv[0])) exit() } - f = File(args["file"], "r") - lines = (String(f.read())).split("\n") + var f = File(args["file"], "r") + var lines = (String(f.read())).split("\n") f.close() - matched_lines = [] - i = 0 + var matched_lines = [] + var i = 0 for line in lines { if args["query"] in line { arr_append(matched_lines, [i, line]) } - nonlocal i++ + i++ } if not is_null(args["--max-lines"]) { - nonlocal matched_lines = matched_lines[:args["--max-lines"]] + var matched_lines = matched_lines[:args["--max-lines"]] } for line in matched_lines { - s = line[1] + var s = line[1] if args["--line-numbers"] { - nonlocal s = args["file"] + ":" + line[0] + ": " + s + var s = args["file"] + ":" + line[0] + ": " + s } print(s) }