wip: findr.
This commit is contained in:
61
findr.odin
61
findr.odin
@@ -2,19 +2,63 @@ package findr
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
|
||||
main :: proc() {
|
||||
args := os.args
|
||||
|
||||
search_dirs := make([dynamic]string)
|
||||
defer delete(search_dirs)
|
||||
opts: WalkOptions
|
||||
opts.include_hidden = true
|
||||
opts.ignore_mode = .Respected
|
||||
|
||||
for i in 1 ..< len(args) {
|
||||
append(&search_dirs, args[i])
|
||||
excludes := make([dynamic]string)
|
||||
defer delete(excludes)
|
||||
|
||||
pattern := ""
|
||||
paths := make([dynamic]string)
|
||||
defer delete(paths)
|
||||
|
||||
i := 1
|
||||
for i < len(args) {
|
||||
arg := args[i]
|
||||
switch {
|
||||
case arg == "-I":
|
||||
opts.ignore_mode = .All
|
||||
case arg == "--ignored":
|
||||
opts.ignore_mode = .Ignored
|
||||
case arg == "--no-hidden":
|
||||
opts.include_hidden = false
|
||||
case arg == "-E":
|
||||
i += 1
|
||||
if i < len(args) {
|
||||
append(&excludes, args[i])
|
||||
}
|
||||
case strings.has_prefix(arg, "-E"):
|
||||
append(&excludes, arg[2:])
|
||||
case len(arg) > 0 && arg[0] == '-':
|
||||
// unknown flag, skip
|
||||
case:
|
||||
if pattern == "" {
|
||||
pattern = arg
|
||||
} else {
|
||||
append(&paths, arg)
|
||||
}
|
||||
}
|
||||
i += 1
|
||||
}
|
||||
|
||||
if len(search_dirs) == 0 {
|
||||
append(&search_dirs, ".")
|
||||
if len(paths) == 0 && pattern != "" && os.exists(pattern) {
|
||||
append(&paths, pattern)
|
||||
pattern = ""
|
||||
}
|
||||
|
||||
opts.pattern = pattern
|
||||
if len(excludes) > 0 {
|
||||
opts.excludes = excludes[:]
|
||||
}
|
||||
|
||||
if len(paths) == 0 {
|
||||
append(&paths, ".")
|
||||
}
|
||||
|
||||
results := make([dynamic]string)
|
||||
@@ -24,12 +68,11 @@ main :: proc() {
|
||||
}
|
||||
|
||||
thread_count := os.get_processor_core_count()
|
||||
for dir in search_dirs {
|
||||
walk(dir, &results, thread_count)
|
||||
for dir in paths {
|
||||
walk(dir, &results, opts, thread_count)
|
||||
}
|
||||
|
||||
for r in results {
|
||||
fmt.println(r)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user