lighten modules and remove unnecessary imports

This commit is contained in:
timurgordon
2025-01-02 01:47:15 -05:00
parent 86af42bf4a
commit 5d3df608e1
6 changed files with 20 additions and 19 deletions

View File

@@ -7,7 +7,7 @@ import os
const testpath3 = os.dir(@FILE) + '/../..'
// if we return True then it means the dir or file is processed
fn filter_1(mut path pathlib.Path, mut params paramsparser.Params) !bool {
fn filter_1(mut path pathlib.Path) !bool {
if path.is_dir() {
if path.path.ends_with('.dSYM') {
return false

View File

@@ -1,10 +1,16 @@
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
type Executor0 = fn (mut Path, mut paramsparser.Params) !paramsparser.Params
// executor is a struct that has a execute method which takes a path
// and performs an execution on it, returning a result
pub interface IExecutor {
execute(Path) !
}
// 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 .
@@ -14,29 +20,29 @@ type Executor0 = fn (mut Path, mut paramsparser.Params) !paramsparser.Params
// type Filter0 = fn (mut Path, mut paramsparser.Params) bool
// 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() {
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")
// walk over filters if any of them returns false return and don't process
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}'
// console.print_debug(msg)
return error(msg)
}
if !needs_to_be_true {
return parameters
return
}
}
if path.is_dir() {
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}'
// console.print_debug(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
for mut p_in in pl.paths {
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}'
// console.print_debug(msg)
return error(msg)
@@ -59,7 +65,7 @@ fn scan_recursive(mut path Path, mut parameters paramsparser.Params, filters []F
// now process the dirs
for mut p_in in pl.paths {
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}'
// console.print_debug(msg)
return error(msg)
@@ -68,12 +74,11 @@ fn scan_recursive(mut path Path, mut parameters paramsparser.Params, filters []F
}
} else {
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}'
// console.print_debug(msg)
return error(msg)
}
}
}
return parameters
}

View File

@@ -1,6 +1,5 @@
module paramsparser
import freeflowuniverse.herolib.data.currency
import os
const testparams = Params{

View File

@@ -3,7 +3,6 @@ module gittools
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.osal
import os
import time
// GitRepo holds information about a single Git repository.
@[heap]

View File

@@ -1,7 +1,6 @@
module gittools
import freeflowuniverse.herolib.ui.console
import freeflowuniverse.herolib.osal
import os
@[params]

View File

@@ -1,6 +1,5 @@
module gittools
import freeflowuniverse.herolib.osal
import freeflowuniverse.herolib.osal.sshagent
import freeflowuniverse.herolib.core.pathlib
import freeflowuniverse.herolib.ui.console