|
|
|
@@ -1,10 +1,16 @@
|
|
|
|
module pathlib
|
|
|
|
module pathlib
|
|
|
|
|
|
|
|
|
|
|
|
import freeflowuniverse.herolib.data.paramsparser
|
|
|
|
// filter is a struct that has a filter method which takes a path
|
|
|
|
|
|
|
|
// and returns whether it should be filtered
|
|
|
|
|
|
|
|
pub interface IFilter {
|
|
|
|
|
|
|
|
filter(Path) !bool
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type Filter0 = fn (mut Path, mut paramsparser.Params) !bool
|
|
|
|
// executor is a struct that has a execute method which takes a path
|
|
|
|
|
|
|
|
// and performs an execution on it, returning a result
|
|
|
|
type Executor0 = fn (mut Path, mut paramsparser.Params) !paramsparser.Params
|
|
|
|
pub interface IExecutor {
|
|
|
|
|
|
|
|
execute(Path) !
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the filters are function which needs to return true if to process with alle executors .
|
|
|
|
// the filters are function which needs to return true if to process with alle executors .
|
|
|
|
// see https://github.com/freeflowuniverse/herolib/blob/development/examples/core/pathlib/examples/scanner/path_scanner.v .
|
|
|
|
// see https://github.com/freeflowuniverse/herolib/blob/development/examples/core/pathlib/examples/scanner/path_scanner.v .
|
|
|
|
@@ -14,29 +20,29 @@ type Executor0 = fn (mut Path, mut paramsparser.Params) !paramsparser.Params
|
|
|
|
// type Filter0 = fn (mut Path, mut paramsparser.Params) bool
|
|
|
|
// type Filter0 = fn (mut Path, mut paramsparser.Params) bool
|
|
|
|
// type Executor0 = fn (mut Path, mut paramsparser.Params) !paramsparser.Params
|
|
|
|
// type Executor0 = fn (mut Path, mut paramsparser.Params) !paramsparser.Params
|
|
|
|
//
|
|
|
|
//
|
|
|
|
pub fn (mut path Path) scan(mut parameters paramsparser.Params, filters []Filter0, executors []Executor0) !paramsparser.Params {
|
|
|
|
pub fn (mut path Path) scan(filters []IFilter, executors []IExecutor) ! {
|
|
|
|
if !path.is_dir() {
|
|
|
|
if !path.is_dir() {
|
|
|
|
return error('can only scan on dir.\n${path}')
|
|
|
|
return error('can only scan on dir.\n${path}')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return scan_recursive(mut path, mut parameters, filters, executors)
|
|
|
|
return scan_recursive(mut path, filters, executors)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn scan_recursive(mut path Path, mut parameters paramsparser.Params, filters []Filter0, executors []Executor0) !paramsparser.Params {
|
|
|
|
fn scan_recursive(mut path Path, filters []IFilter, executors []IExecutor) ! {
|
|
|
|
// console.print_debug("recursive: $path")
|
|
|
|
// console.print_debug("recursive: $path")
|
|
|
|
// walk over filters if any of them returns false return and don't process
|
|
|
|
// walk over filters if any of them returns false return and don't process
|
|
|
|
for f in filters {
|
|
|
|
for f in filters {
|
|
|
|
needs_to_be_true := f(mut path, mut parameters) or {
|
|
|
|
needs_to_be_true := f.filter(path) or {
|
|
|
|
msg := 'Cannot filter for ${path.path}\n${error}'
|
|
|
|
msg := 'Cannot filter for ${path.path}\n${error}'
|
|
|
|
// console.print_debug(msg)
|
|
|
|
// console.print_debug(msg)
|
|
|
|
return error(msg)
|
|
|
|
return error(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !needs_to_be_true {
|
|
|
|
if !needs_to_be_true {
|
|
|
|
return parameters
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if path.is_dir() {
|
|
|
|
if path.is_dir() {
|
|
|
|
for e in executors {
|
|
|
|
for e in executors {
|
|
|
|
parameters = e(mut path, mut parameters) or {
|
|
|
|
e.execute(path) or {
|
|
|
|
msg := 'Cannot process execution on dir ${path.path}\n${error}'
|
|
|
|
msg := 'Cannot process execution on dir ${path.path}\n${error}'
|
|
|
|
// console.print_debug(msg)
|
|
|
|
// console.print_debug(msg)
|
|
|
|
return error(msg)
|
|
|
|
return error(msg)
|
|
|
|
@@ -49,7 +55,7 @@ fn scan_recursive(mut path Path, mut parameters paramsparser.Params, filters []F
|
|
|
|
// first process the files and link
|
|
|
|
// first process the files and link
|
|
|
|
for mut p_in in pl.paths {
|
|
|
|
for mut p_in in pl.paths {
|
|
|
|
if !p_in.is_dir() {
|
|
|
|
if !p_in.is_dir() {
|
|
|
|
scan_recursive(mut p_in, mut parameters, filters, executors) or {
|
|
|
|
scan_recursive(mut p_in, filters, executors) or {
|
|
|
|
msg := 'Cannot process recursive on ${p_in.path}\n${error}'
|
|
|
|
msg := 'Cannot process recursive on ${p_in.path}\n${error}'
|
|
|
|
// console.print_debug(msg)
|
|
|
|
// console.print_debug(msg)
|
|
|
|
return error(msg)
|
|
|
|
return error(msg)
|
|
|
|
@@ -59,7 +65,7 @@ fn scan_recursive(mut path Path, mut parameters paramsparser.Params, filters []F
|
|
|
|
// now process the dirs
|
|
|
|
// now process the dirs
|
|
|
|
for mut p_in in pl.paths {
|
|
|
|
for mut p_in in pl.paths {
|
|
|
|
if p_in.is_dir() {
|
|
|
|
if p_in.is_dir() {
|
|
|
|
scan_recursive(mut p_in, mut parameters, filters, executors) or {
|
|
|
|
scan_recursive(mut p_in, filters, executors) or {
|
|
|
|
msg := 'Cannot process recursive on ${p_in.path}\n${error}'
|
|
|
|
msg := 'Cannot process recursive on ${p_in.path}\n${error}'
|
|
|
|
// console.print_debug(msg)
|
|
|
|
// console.print_debug(msg)
|
|
|
|
return error(msg)
|
|
|
|
return error(msg)
|
|
|
|
@@ -68,12 +74,11 @@ fn scan_recursive(mut path Path, mut parameters paramsparser.Params, filters []F
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
for e in executors {
|
|
|
|
for e in executors {
|
|
|
|
parameters = e(mut path, mut parameters) or {
|
|
|
|
e.execute(path) or {
|
|
|
|
msg := 'Cannot process execution on file ${path.path}\n${error}'
|
|
|
|
msg := 'Cannot process execution on file ${path.path}\n${error}'
|
|
|
|
// console.print_debug(msg)
|
|
|
|
// console.print_debug(msg)
|
|
|
|
return error(msg)
|
|
|
|
return error(msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parameters
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|