Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 20, 2024
1 parent bf1f46a commit 176295e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 14 additions & 12 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,26 @@ impl Config {
}

pub fn get_repo_url(&self, plugin_name: &str) -> Option<String> {
let plugin_name = self
let url = self
.all_aliases
.get(plugin_name)
.and_then(|a| a.backend.clone())
.or_else(|| self.repo_urls.get(plugin_name).cloned())
.unwrap_or(plugin_name.to_string());
let plugin_name = plugin_name.strip_prefix("asdf:").unwrap_or(&plugin_name);
let plugin_name = plugin_name.strip_prefix("vfox:").unwrap_or(plugin_name);
self.get_shorthands()
.get(plugin_name)
.map(|full| registry::full_to_url(&full[0]))
.or_else(|| {
if plugin_name.starts_with("https://") || plugin_name.split('/').count() == 2 {
Some(registry::full_to_url(plugin_name))
} else {
None
}
self.get_shorthands()
.get(plugin_name)
.and_then(|full| full.first().cloned())
})
.unwrap_or(plugin_name.to_string());
let url = url.strip_prefix("asdf:").unwrap_or(&url);
let url = url.strip_prefix("vfox:").unwrap_or(url);
if registry::url_like(url) {
Some(url.to_string())
} else if url.split('/').count() == 2 {
Some(format!("https://github.com/{url}.git"))
} else {
None
}
}

pub fn tasks(&self) -> Result<&BTreeMap<String, Task>> {
Expand Down
2 changes: 1 addition & 1 deletion src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ pub fn full_to_url(full: &str) -> String {
}
}

fn url_like(s: &str) -> bool {
pub fn url_like(s: &str) -> bool {
s.starts_with("https://")
|| s.starts_with("http://")
|| s.starts_with("git@")
Expand Down

0 comments on commit 176295e

Please sign in to comment.