feat(path): add option to accept custom package dir

This commit is contained in:
Federico Terzi 2021-05-16 14:37:12 +02:00
parent e049ba51fb
commit 6cf5b51487
2 changed files with 18 additions and 5 deletions

View File

@ -30,7 +30,11 @@ pub struct Paths {
pub packages: PathBuf,
}
pub fn resolve_paths(force_config_dir: Option<&Path>, force_runtime_dir: Option<&Path>) -> Paths {
pub fn resolve_paths(
force_config_dir: Option<&Path>,
force_package_dir: Option<&Path>,
force_runtime_dir: Option<&Path>,
) -> Paths {
let config_dir = if let Some(config_dir) = force_config_dir {
config_dir.to_path_buf()
} else if let Some(config_dir) = get_config_dir() {
@ -59,7 +63,9 @@ pub fn resolve_paths(force_config_dir: Option<&Path>, force_runtime_dir: Option<
runtime_dir
};
let packages_dir = if let Some(package_dir) = get_packages_dir(&config_dir, &runtime_dir) {
let packages_dir = if let Some(package_dir) = force_package_dir {
package_dir.to_path_buf()
} else if let Some(package_dir) = get_packages_dir(&config_dir, &runtime_dir) {
package_dir
} else {
// Create the packages directory if not already present
@ -71,8 +77,8 @@ pub fn resolve_paths(force_config_dir: Option<&Path>, force_runtime_dir: Option<
Paths {
config: config_dir,
runtime: runtime_dir,
packages: packages_dir,
runtime: runtime_dir,
packages: packages_dir,
}
}

View File

@ -92,6 +92,12 @@ fn main() {
.takes_value(true)
.help("Specify a custom path from which espanso should read the configuration"),
)
.arg(
Arg::with_name("package_dir")
.long("package_dir")
.takes_value(true)
.help("Specify a custom path for the espanso package directory"),
)
.arg(
Arg::with_name("runtime_dir")
.long("runtime_dir")
@ -256,9 +262,10 @@ fn main() {
if handler.requires_paths || handler.requires_config {
let force_config_path = get_path_override(&matches, "config_dir", "ESPANSO_CONFIG_DIR");
let force_package_path = get_path_override(&matches, "package_dir", "ESPANSO_PACKAGE_DIR");
let force_runtime_path = get_path_override(&matches, "runtime_dir", "ESPANSO_RUNTIME_DIR");
let paths = espanso_path::resolve_paths(force_config_path.as_deref(), force_runtime_path.as_deref());
let paths = espanso_path::resolve_paths(force_config_path.as_deref(), force_package_path.as_deref(), force_runtime_path.as_deref());
info!("reading configs from: {:?}", paths.config);
info!("reading packages from: {:?}", paths.packages);