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) + '/../..' const testpath3 = os.dir(@FILE) + '/../..'
// if we return True then it means the dir or file is processed // 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.is_dir() {
if path.path.ends_with('.dSYM') { if path.path.ends_with('.dSYM') {
return false return false

View File

@@ -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
} }

View File

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

View File

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

View File

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

View File

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