Files
herolib/lib/data/paramsparser/params_getpath.v
2024-12-25 09:23:31 +01:00

30 lines
541 B
V

module paramsparser
import os
// will get path and check it exists
pub fn (params &Params) get_path(key string) !string {
mut path := params.get(key)!
path = path.replace('~', os.home_dir())
if !os.exists(path) {
return error('Cannot find path: ${path} was for key:${key}')
}
return path
}
// create the path if it doesn't exist
pub fn (params &Params) get_path_create(key string) !string {
mut path := params.get(key)!
path = path.replace('~', os.home_dir())
if !os.exists(path) {
os.mkdir_all(path)!
}
return path
}