diff --git a/espanso-path/src/lib.rs b/espanso-path/src/lib.rs index 1b1e8e0..d42b577 100644 --- a/espanso-path/src/lib.rs +++ b/espanso-path/src/lib.rs @@ -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, } } diff --git a/espanso/src/main.rs b/espanso/src/main.rs index d0dfa5d..e23fcf9 100644 --- a/espanso/src/main.rs +++ b/espanso/src/main.rs @@ -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);