Skip to content

Commit

Permalink
feat: add more directory env var configs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed May 11, 2024
1 parent 8a322bc commit 3b72aac
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/cli/doctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl Doctor {
}

fn shims_on_path() -> bool {
env::PATH.contains(&*dirs::SHIMS)
env::PATH.contains(&dirs::SHIMS.to_path_buf())
}

fn yn(b: bool) -> String {
Expand All @@ -215,7 +215,7 @@ fn mise_dirs() -> String {
("config", &*dirs::CONFIG),
("cache", &*dirs::CACHE),
("state", &*dirs::STATE),
("shims", &dirs::SHIMS.as_path()),
("shims", &*dirs::SHIMS),
]
.iter()
.map(|(k, p)| format!("{k}: {}", display_path(p)))
Expand Down
10 changes: 5 additions & 5 deletions src/cli/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ mod tests {

#[test]
fn test_ls() {
let _ = remove_all(dirs::INSTALLS.as_path());
let _ = remove_all(*dirs::INSTALLS);
assert_cli!("install");
assert_cli_snapshot!("list", @r###"
dummy ref:master ~/.test-tool-versions ref:master
Expand All @@ -396,14 +396,14 @@ mod tests {
assert_cli!("install", "tiny@2.0.0");
assert_cli_snapshot!("list", @r###"
dummy ref:master ~/.test-tool-versions ref:master
tiny 2.0.0
tiny 2.0.0
tiny 3.1.0 ~/cwd/.test-tool-versions 3
"###);

assert_cli!("uninstall", "tiny@3.1.0");
assert_cli_snapshot!("list", @r###"
dummy ref:master ~/.test-tool-versions ref:master
tiny 2.0.0
tiny 2.0.0
tiny 3.1.0 (missing) ~/cwd/.test-tool-versions 3
"###);

Expand All @@ -430,15 +430,15 @@ mod tests {

#[test]
fn test_ls_json() {
let _ = remove_all(dirs::INSTALLS.as_path());
let _ = remove_all(*dirs::INSTALLS);
assert_cli!("install");
assert_cli_snapshot!("ls", "--json");
assert_cli_snapshot!("ls", "--json", "tiny");
}

#[test]
fn test_ls_parseable() {
let _ = remove_all(dirs::INSTALLS.as_path());
let _ = remove_all(*dirs::INSTALLS);
assert_cli!("install");
assert_cli_snapshot!("ls", "--parseable", @r###"
dummy ref:master
Expand Down
2 changes: 1 addition & 1 deletion src/cli/plugins/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl PluginsLink {
));
}
}
file::create_dir_all(&*dirs::PLUGINS)?;
file::create_dir_all(*dirs::PLUGINS)?;
make_symlink(&path, &symlink)?;
Ok(())
}
Expand Down
8 changes: 4 additions & 4 deletions src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub static CONFIG: Lazy<&Path> = Lazy::new(|| &env::MISE_CONFIG_DIR);
pub static STATE: Lazy<&Path> = Lazy::new(|| &env::MISE_STATE_DIR);
pub static SYSTEM: Lazy<&Path> = Lazy::new(|| &env::MISE_SYSTEM_DIR);

pub static PLUGINS: Lazy<PathBuf> = Lazy::new(|| DATA.join("plugins"));
pub static DOWNLOADS: Lazy<PathBuf> = Lazy::new(|| DATA.join("downloads"));
pub static INSTALLS: Lazy<PathBuf> = Lazy::new(|| DATA.join("installs"));
pub static SHIMS: Lazy<PathBuf> = Lazy::new(|| DATA.join("shims"));
pub static PLUGINS: Lazy<&Path> = Lazy::new(|| &env::MISE_PLUGINS_DIR);
pub static DOWNLOADS: Lazy<&Path> = Lazy::new(|| &env::MISE_DOWNLOADS_DIR);
pub static INSTALLS: Lazy<&Path> = Lazy::new(|| &env::MISE_INSTALLS_DIR);
pub static SHIMS: Lazy<&Path> = Lazy::new(|| &env::MISE_SHIMS_DIR);

pub static TRACKED_CONFIGS: Lazy<PathBuf> = Lazy::new(|| STATE.join("tracked-configs"));
pub static TRUSTED_CONFIGS: Lazy<PathBuf> = Lazy::new(|| STATE.join("trusted-configs"));
10 changes: 10 additions & 0 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ pub static MISE_TMP_DIR: Lazy<PathBuf> =
pub static MISE_SYSTEM_DIR: Lazy<PathBuf> =
Lazy::new(|| var_path("MISE_SYSTEM_DIR").unwrap_or_else(|| PathBuf::from("/etc/mise")));

// data subdirs
pub static MISE_INSTALLS_DIR: Lazy<PathBuf> =
Lazy::new(|| var_path("MISE_INSTALLS_DIR").unwrap_or_else(|| MISE_DATA_DIR.join("installs")));
pub static MISE_DOWNLOADS_DIR: Lazy<PathBuf> =
Lazy::new(|| var_path("MISE_DOWNLOADS_DIR").unwrap_or_else(|| MISE_DATA_DIR.join("downloads")));
pub static MISE_PLUGINS_DIR: Lazy<PathBuf> =
Lazy::new(|| var_path("MISE_PLUGINS_DIR").unwrap_or_else(|| MISE_DATA_DIR.join("plugins")));
pub static MISE_SHIMS_DIR: Lazy<PathBuf> =
Lazy::new(|| var_path("MISE_SHIMS_DIR").unwrap_or_else(|| MISE_DATA_DIR.join("shims")));

pub static MISE_DEFAULT_TOOL_VERSIONS_FILENAME: Lazy<String> = Lazy::new(|| {
var("MISE_DEFAULT_TOOL_VERSIONS_FILENAME").unwrap_or_else(|_| ".tool-versions".into())
});
Expand Down
14 changes: 11 additions & 3 deletions src/path_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@ impl PathEnv {
}

pub fn to_vec(&self) -> Vec<PathBuf> {
let mut paths = self.pre.iter().chain(self.mise.iter()).collect_vec();
let mut paths = self
.pre
.iter()
.chain(self.mise.iter())
.map(|p| p.to_path_buf())
.collect_vec();
if self.seen_shims {
paths.push(&dirs::SHIMS);
paths.push(dirs::SHIMS.to_path_buf())
}
paths.into_iter().chain(self.post.iter()).cloned().collect()
paths
.into_iter()
.chain(self.post.iter().map(|p| p.to_path_buf()))
.collect()
}

pub fn join(&self) -> OsString {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/external_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ fn build_script_man(name: &str, plugin_path: &Path) -> ScriptManager {
.with_env("ASDF_PLUGIN_PATH", plugin_path_s.clone())
.with_env("RTX_PLUGIN_PATH", plugin_path_s.clone())
.with_env("RTX_PLUGIN_NAME", name.to_string())
.with_env("RTX_SHIMS_DIR", &*dirs::SHIMS)
.with_env("RTX_SHIMS_DIR", *dirs::SHIMS)
.with_env("MISE_PLUGIN_NAME", name.to_string())
.with_env("MISE_PLUGIN_PATH", plugin_path)
.with_env("MISE_SHIMS_DIR", &*dirs::SHIMS)
.with_env("MISE_SHIMS_DIR", *dirs::SHIMS)
}

impl Eq for ExternalPlugin {}
Expand Down
4 changes: 2 additions & 2 deletions src/shims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn which_shim(bin_name: &str) -> Result<PathBuf> {
// fallback for "system"
for path in &*env::PATH {
if fs::canonicalize(path).unwrap_or_default()
== fs::canonicalize(&*dirs::SHIMS).unwrap_or_default()
== fs::canonicalize(*dirs::SHIMS).unwrap_or_default()
{
continue;
}
Expand All @@ -94,7 +94,7 @@ pub fn reshim(ts: &Toolset) -> Result<()> {

let mise_bin = file::which("mise").unwrap_or(env::MISE_BIN.clone());

create_dir_all(&*dirs::SHIMS)?;
create_dir_all(*dirs::SHIMS)?;

let (shims_to_add, shims_to_remove) = get_shim_diffs(&mise_bin, ts)?;

Expand Down

0 comments on commit 3b72aac

Please sign in to comment.