Skip to content

Commit

Permalink
fix: var declaration and module name update.
Browse files Browse the repository at this point in the history
  • Loading branch information
Almas-Ali committed Jul 21, 2024
1 parent 88918d0 commit 67c8404
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions examples/simple-grep.rn
Original file line number Diff line number Diff line change
@@ -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)
}
Expand Down

0 comments on commit 67c8404

Please sign in to comment.