Skip to content
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
5 changes: 5 additions & 0 deletions e2e/cli/test_ls
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

mise i cargo:usage-cli
assert_contains "mise ls" "cargo:usage-cli"
assert_not_contains "mise ls" "cargo-usage-cli" # if the backend meta file isn't working right these will be displayed
4 changes: 2 additions & 2 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn load_tools() {
})
.unwrap_or_default()
.into_values()
.map(|ist| arg_to_backend(BackendArg::new(ist.short, Some(ist.full))).unwrap()),
.flat_map(|ist| arg_to_backend(BackendArg::new(ist.short, Some(ist.full)))),
);
time!("load_tools install_state");
tools.retain(|backend| !SETTINGS.disable_tools.contains(backend.id()));
Expand Down Expand Up @@ -598,7 +598,7 @@ pub trait Backend: Debug + Send + Sync {
fn write_backend_meta(&self) -> eyre::Result<()> {
file::write(
self.ba().installs_path.join(".mise.backend"),
self.ba().full(),
format!("{}\n{}", self.ba().short, self.ba().full()),
)
}
}
Expand Down
36 changes: 26 additions & 10 deletions src/toolset/install_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type InstallStateTools = BTreeMap<String, InstallStateTool>;
#[derive(Debug, Clone)]
pub struct InstallStateTool {
pub short: String,
pub _dir: PathBuf,
pub full: String,
pub backend_type: BackendType,
pub versions: Vec<String>,
Expand Down Expand Up @@ -67,6 +68,7 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
.map(|(short, pt)| {
let tool = InstallStateTool {
short: short.clone(),
_dir: dirs::PLUGINS.join(short),
backend_type: match pt {
PluginType::Asdf => BackendType::Asdf,
PluginType::Vfox => BackendType::Vfox,
Expand All @@ -83,9 +85,12 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
let dirs = file::dir_subdirs(&dirs::INSTALLS)?;
tools.extend(
dirs.into_iter()
.map(|short| {
let dir = dirs::INSTALLS.join(&short);
let full = if let Some(full) = short_to_full(&short)? {
.map(|dir| {
let backend_meta = read_backend_meta(&dir).unwrap_or_default();
let short = backend_meta.first().unwrap_or(&dir).to_string();
let full = backend_meta.get(1).cloned();
let dir = dirs::INSTALLS.join(&dir);
let full = if let Some(full) = short_to_full(&short, full)? {
full
} else {
return Ok(None);
Expand All @@ -104,6 +109,7 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
.collect();
let tool = InstallStateTool {
short: short.clone(),
_dir: dir.clone(),
full,
backend_type,
versions,
Expand All @@ -119,15 +125,15 @@ fn init_tools() -> Result<MutexGuard<'static, Option<BTreeMap<String, InstallSta
Ok(mu)
}

pub fn short_to_full(short: &str) -> Result<Option<String>> {
pub fn short_to_full(short: &str, meta_full: Option<String>) -> Result<Option<String>> {
let plugins = init_plugins()?;
let plugins = plugins.as_ref().unwrap();
if let Some(plugin) = plugins.get(short) {
match plugin {
PluginType::Asdf => Ok(Some(format!("asdf:{short}"))),
PluginType::Vfox => Ok(Some(format!("vfox:{short}"))),
}
} else if let Some(full) = read_backend_meta(short) {
} else if let Some(full) = meta_full {
Ok(Some(full))
} else if let Some(full) = REGISTRY
.get(short)
Expand Down Expand Up @@ -183,12 +189,17 @@ fn backend_meta_path(short: &str) -> PathBuf {
dirs::INSTALLS.join(short).join(".mise.backend")
}

fn migrate_backend_meta_json(short: &str) {
let old = dirs::INSTALLS.join(short).join(".mise.backend.json");
fn migrate_backend_meta_json(dir: &str) {
let old = dirs::INSTALLS.join(dir).join(".mise.backend.json");
let migrate = || {
let json: serde_json::Value = serde_json::from_reader(file::open(&old)?)?;
if let Some(full) = json.get("id").and_then(|id| id.as_str()) {
file::write(backend_meta_path(short), full.trim())?;
let short = json
.get("short")
.and_then(|short| short.as_str())
.unwrap_or(dir);
let doc = format!("{}\n{}", short, full);
file::write(backend_meta_path(dir), doc.trim())?;
}
Ok(())
};
Expand All @@ -202,7 +213,7 @@ fn migrate_backend_meta_json(short: &str) {
}
}

fn read_backend_meta(short: &str) -> Option<String> {
fn read_backend_meta(short: &str) -> Option<Vec<String>> {
migrate_backend_meta_json(short);
let path = backend_meta_path(short);
if path.exists() {
Expand All @@ -211,7 +222,12 @@ fn read_backend_meta(short: &str) -> Option<String> {
warn!("{err:?}");
})
.unwrap_or_default();
Some(body)
Some(
body.lines()
.filter(|f| !f.is_empty())
.map(|f| f.to_string())
.collect(),
)
} else {
None
}
Expand Down