Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add more directory env var configs #2056

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
#- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-toml
Expand Down
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
6 changes: 3 additions & 3 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 Down Expand Up @@ -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