Skip to content

Commit

Permalink
support SNM_HOME_DIR env
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Jul 19, 2024
1 parent 4ee8a25 commit 4ce1a30
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/snm_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use snm_node_version::{parse_node_version, NodeVersion};
use snm_npmrc::parse_npmrc;
use snm_package_json::{package_manager_meta::PackageManager, parse_package_json, PackageJson};
use snm_utils::snm_error::SnmError;
use std::{env, path::PathBuf};
use std::{env, f32::consts::E, path::PathBuf};

#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
pub enum InstallStrategy {
Expand Down Expand Up @@ -38,6 +38,7 @@ impl InstallStrategy {
}
}

const SNM_HOME_DIR_KEY: &str = "SNM_HOME_DIR";
const SNM_NODE_VERSION_ENV_KEY: &str = "SNM_NODE_VERSION";
const SNM_PACKAGE_MANAGER_NAME_ENV_KEY: &str = "SNM_PACKAGE_MANAGER_NAME";
const SNM_PACKAGE_MANAGER_VERSION_ENV_KEY: &str = "SNM_PACKAGE_MANAGER_VERSION";
Expand Down Expand Up @@ -86,11 +87,14 @@ pub struct SnmConfig {

impl SnmConfig {
fn get_base_dir(&self) -> Result<PathBuf, SnmError> {
match dirs::home_dir() {
Some(home_dir) => Ok(home_dir.join(".snm")),
None => {
return Err(SnmError::GetHomeDirError);
}
match env::var(SNM_HOME_DIR_KEY) {
Ok(dir) => Ok(PathBuf::from(dir)),
Err(_) => match dirs::home_dir() {
Some(dir) => Ok(dir.join(".snm")),
None => {
return Err(SnmError::GetHomeDirError);
}
},
}
}

Expand Down

0 comments on commit 4ce1a30

Please sign in to comment.