Browse Source

Make the first installed version the default one (#304)

remotes/origin/add-with-shims
Gal Schlezinger 4 years ago committed by GitHub
parent
commit
538c907ad7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      src/commands/install.rs
  2. 6
      src/config.rs

38
src/commands/install.rs

@ -112,6 +112,11 @@ impl super::command::Command for Install { @@ -112,6 +112,11 @@ impl super::command::Command for Install {
create_alias(&config, &alias_name, &version).context(IoError)?;
}
if !config.default_version_dir().exists() {
debug!("Tagging {} as the default version", version.v_str().cyan());
create_alias(&config, "default", &version).context(IoError)?;
}
Ok(())
}
}
@ -151,3 +156,36 @@ pub enum Error { @@ -151,3 +156,36 @@ pub enum Error {
#[snafu(display("Too many versions provided. Please don't use --lts with a version string."))]
TooManyVersionsProvided,
}
#[cfg(test)]
mod tests {
use super::super::command::Command;
use super::*;
use pretty_assertions::assert_eq;
use std::str::FromStr;
#[test]
fn test_set_default_on_new_installation() {
let base_dir = tempfile::tempdir().unwrap();
let config = FnmConfig::default().with_base_dir(Some(base_dir.path().to_path_buf()));
assert!(!config.default_version_dir().exists());
Install {
version: UserVersion::from_str("12.0.0").ok(),
lts: false,
}
.apply(&config)
.expect("Can't install");
assert!(config.default_version_dir().exists());
assert_eq!(
config.default_version_dir().canonicalize().ok(),
config
.installations_dir()
.join("v12.0.0")
.join("installation")
.canonicalize()
.ok()
);
}
}

6
src/config.rs

@ -66,6 +66,12 @@ impl FnmConfig { @@ -66,6 +66,12 @@ impl FnmConfig {
pub fn aliases_dir(&self) -> std::path::PathBuf {
ensure_exists_silently(self.base_dir_with_default().join("aliases"))
}
#[cfg(test)]
pub fn with_base_dir(mut self, base_dir: Option<std::path::PathBuf>) -> Self {
self.base_dir = base_dir;
self
}
}
fn ensure_exists_silently<T: AsRef<std::path::Path>>(path: T) -> T {

Loading…
Cancel
Save